【发布时间】:2019-05-30 02:05:56
【问题描述】:
我试图在不同的时间用不同的原型单元格填充 tableView。问题是let cell = tableView.dequeueReusableCell(withIdentifier: "MeArticlesCell") as? MeArticlesCell else {return UITableViewCell()} 之后的任何代码都没有被调用,我不知道为什么。我返回正确的行数。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(postsSelected){
guard let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell") as? feedMessagesCell else {return UITableViewCell()}
//the code in this part loads posts fine
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "messageCell") as? feedMessagesCell else {return UITableViewCell()}
//this part never gets called
}
}
【问题讨论】:
-
当您写
//this part never gets called时,您指的是guard let声明?或者之后会发生什么? -
更正:它确实被调用,但在调用该行之后没有任何内容
-
在 if 语句之前尝试
print(postsSelected)。它很可能总是正确的,因此永远不会进入else声明 -
这不是我已经检查过的问题
-
那么我们需要更多信息。只需在
else语句中打印一些内容,就可以弄清楚“这部分永远不会被调用”。
标签: ios swift uitableview tableview