我是新手。我试图在UITableViewController的两个原型单元中添加两个不同的按钮。这些按钮将导致不同的动作。我已经按照以下方式进行了操作,但是没有成功,请任何人仔细阅读我的代码,让我知道我要去哪里了。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let addPhotocell = tableView.dequeueReusableCellWithIdentifier(cellArray[indexPath.row]) as! AddPhotoTableViewCell
    if (indexPath.row == 1){
        addPhotocell.camera.image = UIImage(named: "icon-camera")
        addPhotocell.addphoto.tag = indexPath.row
        addPhotocell.addphoto.addTarget(self, action: "addPhoto", forControlEvents: UIControlEvents.TouchUpInside)
    }

    if (indexPath.row == 2){

        addPhotocell.gallery.image = UIImage(named: "icon-gallery")
        addPhotocell.choosefromgallery.tag = indexPath.row
        addPhotocell.choosefromgallery.addTarget(self, action: "gallery", forControlEvents: UIControlEvents.TouchUpInside)
    }

    // Configure the cell...
    addPhotocell.backgroundColor = UIColor.clearColor()
    addPhotocell.selectionStyle = .None
    return addPhotocell;

}

最佳答案

您不能只在Interface Builder中添加按钮吗?有什么我想念的吗?

09-25 17:30