Mas*_*owe 1 tableview custom-cell nsindexpath segue swift
我有一个tableView.当点击/选择单元格时,单元格向下展开以显示多个资产.一个资产是文本字段.另一个是"提交"按钮.
当按下Submit按钮时,我需要从文本字段访问用户输入.我怎样才能做到这一点?
重要提示:由于已经选择/扩展了单元格,因此无法使用didSelectRowAtIndexpath.
目前我在customCell上有以下内容:
@IBAction func submitButtonPressed(sender: UIButton) {
    // prepareForSegue is on mainVC
    self.textString = self.textField.text
    println(self.textString) 
 }
在MainVC的"prepareForSegue"中,我有以下内容:
       var cell : CustomCell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as! CustomCell
        let path = self.tableView.indexPathForSelectedRow()!
            println(cell.textField.text)
            self.newText = cell.textString
            self.newInt = self.newText.toInt()
            println(self.newText)
            println(self.newInt)
以下代码正确prints(self.textString)
然而
 cell.textString,self.newText并且self.newInt始终如此nil.  
知道为什么吗?
这是一个示例代码.
@IBAction func submitButtonPressed(sender: UIButton) {
        // prepareForSegue is on mainVC
            let indexPath = self.tableView!.indexPathForSelectedRow()!
            let selectedCell = self.tableView!.cellForRowAtIndexPath(selectedIndexPath!) as! UICustomCell!//your custom cell class.
            self.textString = selectedCell.textFied.text //textFied is your textfield name.
            println(self.textString) 
 }
对于swift 2,此代码基于行索引工作
let indexPath = NSIndexPath(forRow: 1, inSection: 0) // This defines what indexPath is which is used later to define a cell
                let selectedCell = sptableViewObj.cellForRowAtIndexPath(indexPath) as! AddBillerTableViewCell!
                self.textFieldTwo = selectedCell.spTextfield.text //textFied is your textfield name.
                print(self.textFieldTwo)
| 归档时间: | 
 | 
| 查看次数: | 4760 次 | 
| 最近记录: |