【发布时间】:2017-01-23 18:53:07
【问题描述】:
我想在我的项目中使用https://github.com/intuit/AnimatedFormFieldTableViewCell,但我无法理解设置它的步骤。到目前为止,我已经从文件夹中拖出文件并按照以下步骤操作:
要使用AnimatedFormFieldTableViewCell,您只需:
1) 在要实现 UITableView 的 ViewController 上注册 AnimatedFormFieldTableViewCell nib 以作为重用标识符。
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) 您仍然可以像在常规 UITextField 上实现相同的方式实现 UITextFieldDelegate,您只需要定义 AnimatedFormFieldTableViewCell 的委托(无需直接为嵌入式 UITextField 定义委托)。
2) 要访问嵌入的 UITextField,您只需调用单元格的 cellTextField 属性即可。
I don’t get these last two steps.
如果我运行我的应用程序,我会在 AnimatedFormFieldTableViewCell 类中的 self.cellTextfield.delegate = self 上获得 unexpectedly found nil。
我错过了什么?
【问题讨论】:
-
您在哪里访问
cellTextField?您能否也包括该代码?文档明确指出there is no need to directly define the delegate for the embedded UITextField。您可能应该将self.delegate设置为您想要的委托,而不是self.cellTextField.delegate。 -
@MichaelFourre 我不明白。我没有访问
cellTextField。我也没有实现UITextFieldDelegate。我不知道该怎么做。我遇到错误的self.cellTextField.delegate是在AnimatedFormFieldTableViewCell类中实现的,而不是在我的类中实现的。 -
@MichaelFourre 不访问
cellTextField可能是我收到意外发现的 nil 错误的原因。但我想按顺序按照步骤正确实施。 -
好吧,我现在明白了。 @waseefakhtar 让我看看我是否能弄清楚发生了什么
-
@waseefakhtar,我在我的项目中测试了
AnimatedFormFieldTableViewCell,没问题,那么,你的意思是什么?
标签: ios swift uitableview uitextfield