我想在我的項目中使用https://github.com/intuit/AnimatedFormFieldTableViewCell,但我無法擺脫設置它的步驟。到目前爲止,我已經拖從文件夾中的文件和遵循的步驟爲:正在實施UITextFieldDelegate
爲了使用AnimatedFormFieldTableViewCell
,所有你需要做的是:
1)註冊AnimatedFormFieldTableViewCell
筆尖上的ViewController上你正在爲你的重用標識符實現你的UITableView。
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerCellNib(AnimatedFormFieldTableViewCell)
tableView.reloadData()
}
2)出列上的cellForRowAtIndexPath作爲AnimatedFormFieldTableViewCell你的細胞。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AnimatedFormFieldTableViewCell
return cell
}
3)通過調用setLabelText對細胞本身更改佔位符的標籤文本。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! AnimatedFormFieldTableViewCell
cell.setLabelText("Enter title")
return cell
}
注:
1)您仍可以實現UITextFieldDelegate你會定期的UITextField實現相同的方式,你只需要定義AnimatedFormFieldTableViewCell的代表(也沒有必要直接定義委託嵌入的UITextField)。
2)爲了訪問嵌入的UITextField,你可以簡單地調用單元格的cellTextField屬性。
I don’t get these last two steps.
如果我跑我的應用程序,我得到self.cellTextfield.delegate = self
的unexpectedly found nil
在AnimatedFormFieldTableViewCell
類。
我錯過了什麼?
你在哪裏訪問'cellTextField'有什麼不同?你能否也包括那些代碼?該文檔明確指出'不需要直接爲嵌入的UITextField定義委託。你應該設置'self.delegate'到你想要的委託而不是'self.cellTextField.delegate'。 –
@MichaelFourre我不明白。我沒有訪問'cellTextField'。我也沒有實現'UITextFieldDelegate'。我不知道如何。我得到錯誤的'self.cellTextField.delegate'是在'AnimatedFormFieldTableViewCell'類中實現的,而不是在我的。 – waseefakhtar
@MichaelFourre沒有訪問'cellTextField'可能是爲什麼我得到意外發現的零錯誤。但我希望按照這些步驟順序執行。 – waseefakhtar