我有一個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它的標籤? –