Objective c 为什么tableView退出队列ReusableCellWithIdentifier:CellIdentifier返回null?
我正在使用xCode 4.2构建一个iPhone应用程序 我不知道为什么这个语句Objective c 为什么tableView退出队列ReusableCellWithIdentifier:CellIdentifier返回null?,objective-c,uitableview,Objective C,Uitableview,我正在使用xCode 4.2构建一个iPhone应用程序 我不知道为什么这个语句UITableViewCell*cell=[tableView-dequeueReusableCellWithIdentifier:CellIdentifier]有时为空,其他时间不为空。我将陈述两种情况,第一种是单元格不为null,第二种是单元格为null。让我从继承UITableViewController的WSCSSessionTable中两个场景共享的示例代码开始: - (UITableViewCell *)
UITableViewCell*cell=[tableView-dequeueReusableCellWithIdentifier:CellIdentifier]代码>有时为空,其他时间不为空。我将陈述两种情况,第一种是单元格不为null,第二种是单元格为null。让我从继承UITableViewController的WSCSSessionTable中两个场景共享的示例代码开始:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// we have null
}
return cell;
}
场景1-单元格不为空
单元格不是空的,当我像这样设置故事板时,一切正常
场景2-单元格为空
当我这样设置情节提要时,单元格始终为空:
这是实例化表的按钮的事件处理程序
- (IBAction)goToSession:(id)sender
{
wscAppDelegate *appDelegate = (wscAppDelegate *)[[UIApplication sharedApplication] delegate];
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
wscSessions *childView = [storyboard instantiateViewControllerWithIdentifier:@"sessionstable"];
// wscSessions *childView = [storyboard instantiateViewControllerWithIdentifier:@"sessionstable"];
childView._arrData = appDelegate._arrSession;
childView._arrSpeaker = appDelegate._arrSpeaker;
childView.title = @"SEssions";
[self.navigationController pushViewController:childView animated:YES];
}
有人知道为什么场景2中的单元格总是空的吗?它在我的代码的其他地方引起了问题
其他信息
有两个人告诉我不要确保单元格标识符设置为“cell”。这是一个屏幕截图,对吗?场景1和场景2中都是这样。
检查情节提要场景中不工作的单元标识符。现在还不清楚你是否有两个场景,或者你只是在重新安排你的故事板。我正在重新安排我的故事板。单元格标识符在那里。@jrturton所说的是确保在第二个单元格中,表视图单元格的单元格标识符(在故事板中设置)设置为单元格。@Inafziger-我在附加信息中添加了一个屏幕截图。我是否正确设置了单元格标识符?是否在if(cell==nil)
检查中实例化了单元格对象?