【发布时间】:2015-05-11 09:38:31
【问题描述】:
我有一个表格视图。当点击/选择单元格时,单元格会向下扩展以显示多个资产。一项资产是文本字段。另一个是“提交”按钮。
按下提交按钮时,我需要从文本字段访问用户输入。我该怎么做?
重要提示:我无法使用 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。
知道为什么吗?
【问题讨论】:
-
给它一个唯一的标签,然后在视图中搜索带有该标签的元素
-
标签是什么意思?不是 cell.textString 是标签吗?
标签: swift tableview segue custom-cell nsindexpath