【发布时间】:2015-06-11 22:28:27
【问题描述】:
我正在尝试在我的 tableView 中获取一个带有 textView 的自定义 tableView 单元格。我制作了一个自定义 UITableViewCell,里面有一个 textView。
我可以让自定义的 UITableViewCell 与里面的 textView 出现在 UITableView 中。
我可以在 textView 内部单击以输入内容,但是当我完成输入并单击另一个 tableViewCell 时,第一个带有 textView 的 tableViewCell 消失了。消失后,变成了一个空的tableViewCell。 XCode 给出这个消息: "没有重复使用表格单元格的索引路径"
但是,当我在 tableView 中滚动并回滚到空的 tableViewCell 时,它会重新出现。 我不知道如何防止 tableViewCell 消失。似乎答案与在 UITableView 中使用 restoreIdentifier 有关,但我不确定如何使用它。在文档中,它说使用 restoreIdentifier 进行状态保存。
这是我的相关代码:
inside ViewDidLoad():
tableView.registerClass(PhotoAndRateTableViewCell.classForCoder(), forCellReuseIdentifier: ReuseIds.reviewCell)
tableView.registerNib(UINib(nibName: "PhotoAndRateTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: ReuseIds.reviewCell)
cellForRowAtIndexPath 内:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var section = indexPath.section
let cell = UITableViewCell()
var cell = tableView.dequeueReusableCellWithIdentifier(ReuseIds.reviewCell, forIndexPath: indexPath) as PhotoAndRateTableViewCell
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
【问题讨论】:
-
你在哪里创建你的文本视图?
-
在自定义tableViewCell的xib文件中创建textView。文件是 PhotoAndRateTableViewCell.xib 这样我就可以使用 autoLayout 了。
-
我现在可以使用 func textViewDidEndEditing(textView: UITextView) { tableView.reloadData() } 让 tableViewCell 重新出现。但是,里面的数据似乎没有得到保留。
标签: ios swift uitableview