2017-01-28 38 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; 
} 
相關問題