[英]Different heights for 2 different reusable cells in tableview
我有一个包含2个不同的自定义单元格的tableview,它们都具有自己唯一的可重用单元格标识符。 我需要这些具有不同的高度。 我的cellForRowAtIndexPath
看起来像这样:
//3
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell? {
let PostObject = object as! Post
if PostObject["fichierimage"] as? PFFile == nil {
let cell2 = tableView.dequeueReusableCellWithIdentifier("cell10", forIndexPath: indexPath) as! cell0Entry
return cell2
}
else {
let cell = tableView.dequeueReusableCellWithIdentifier("cell9", forIndexPath: indexPath) as! cell4
return cell
}
}
这样可以将所有数据正确加载到表视图中。 但是,两个单元格的高度均保持在481,而第一个单元格的高度应为99。我在情节提要中将其高度设置为99,但我认为tableView行高将其覆盖。 我在heightForRowAtIndexPath
尝试了此操作,但没有成功,它引发了错误并使应用程序崩溃:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let object1 = objectAtIndexPath(indexPath)
let object2 = object1 as! Post
// this next line throws the error
if object2["fichierimage"] as? PFFile == nil {
return 99
}
else {
return 481
}
}
错误消息显示:
由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[__ NSArrayM objectAtIndex:]:索引2超出范围[0 .. 1]
修改
// this next line throws the error
if object2["fichierimage"] as? PFFile == nil {
return 99
}
else {
return 481
}
对此:
if let _ = object2["fichierimage"] as? PFFile {
return 99
}
else {
return 481
}
告诉我是否可行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.