2017-01-28 37 views
0

我尝试做一个待办事项应用程序。 我使用的原型单元格,我目前遇到一个问题,当我按下按钮时,没有任何反应swift 3原型单元格当前行按钮

到目前为止这工作得到按钮的行。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath) as! TableViewCell 

    let task = tasks[indexPath.row] 


    cell.uncheckbox.tag = indexPath.row 
    cell.uncheckbox.addTarget(self, action: #selector(ViewController.Test), for: UIControlEvents.touchUpInside) 

    cell.textField.isEnabled = false 
    cell.importantImage.isHidden = true 


    if(task.isImportant){ 
     cell.textField?.text = task.name! 
     cell.importantImage.isHidden = false; 
    }else{ 
     cell.textField?.text = task.name! 
    } 

    return cell; 
} 

@IBAction func Test(sender: UIButton) 
{ 
    let row = sender.tag 

    let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell") as! TableViewCell 

    print(row) 
    print(row == 0) 
    if(row == 0){ 

     cell.textField?.text = "change the text" 
    } 



} 

的问题是,一旦我按下按钮没有任何反应到当前单元格。我想它还没有设置在正确的行中。

当我刚打印的行,然后按下按钮,我从按钮得到正确的值

+0

找到了另一个解决方案! 感谢您的帮助 –

+0

您能否展示您的解决方案?否则对别人没用 – muescha

回答

0

找到一种方法来做到这一点:

我叫TableViewCell类中的按钮

// when i press the add button it checks all buttons 
@IBAction func testing(_ sender: Any) { 
    if(isBoxClicked == true) 
    { 
     uncheckbox.setImage(checkBox, for: UIControlState.normal) 
     self.textField.backgroundColor = UIColor.red 
     isBoxClicked = false 
    }else{ 
     uncheckbox.setImage(uncheckBox, for: UIControlState.normal) 
     self.textField.backgroundColor = UIColor.white 
     isBoxClicked = true 
    } 
} 

和vieClass内我用这个

FUNC的tableView(_的tableView:UITableView的,cellForRowAt indexPath:IndexPath) - >的UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath) as! TableViewCell 

cell.testing(cell.uncheckbox)

return cell; 
} 
相关问题