我有一个tableView。当单元格被轻敲/选中时,单元格向下展开以显示多个资产。一个资产是一个文本字段。另一个是“提交”按钮。访问tableView中的文本字段SWIFT
当按下“提交”按钮时,我需要从文本字段访问用户输入。我怎样才能做到这一点?
重要说明:我无法使用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
。
任何想法为什么?
给它一个独特的标记,然后用该标签 – Jasper
你是什么意思,标签搜索视图的元素?不是cell.textString它的标签? –