【发布时间】:2014-07-28 23:10:50
【问题描述】:
我正在使用 Swift 开发 iOS 应用程序,我知道该应用程序目前处于测试阶段,但到目前为止,我已经能够解决所有小问题,直到遇到这个问题。我有一个表格视图,它将由 FavoriteRowCell 类的自定义表格单元格填充。这是课程(我已经简化了,希望通过消除过程来解决它):
class FavoriteRowCell
:UITableViewCell {
var data:ImageInfo?;
init() {
super.init(style: UITableViewCellStyle.Default, reuseIdentifier: "favoritesIdentifier");
}
func setData(data:ImageInfo) {
self.data = data;
}
}
这是我的 UITableViewDataSource 实现中的单元回收逻辑:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:FavoriteRowCell? = tableView.dequeueReusableCellWithIdentifier("favoritesIdentifier") as? FavoriteRowCell;
if(!cell) {
cell = FavoriteRowCell();
}
var data:ImageInfo = favorites[indexPath!.row];
cell!.setData(data);
return cell!;
}
当我在模拟器中运行它时,一切正常。然而,当我在我的测试 iPod Touch 上运行它时,我得到一个 NSMallocException 并且应用程序崩溃了。当它尝试创建 FavoriteRowCell 对象时会发生这种情况,但我不知道为什么。
有没有人遇到过类似的事情,或者有什么你能看出我可能做错了吗?
【问题讨论】:
-
你在使用故事板吗?
-
我不是。带有以编程方式创建的 UI 的空 iOS 项目。
标签: ios uitableview malloc swift