我想在我的项目中使用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