[英]cell is nil in prototype cell
我是iPhone开发的新手,我有一个问题,我的应用程序包含从按钮单击到tableView
导航(我使用故事板)。 我创建了custum原型cell
,它的类和标识符。 但是在我调试的方法中,它涉及到cell==nil
和thow exeption:' NSInternalInconsistencyException
',原因:'无法在捆绑包中加载NIB
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"transportTableCell";
CNTransportCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSLog(@"size of %d",transportArray.count);
cell.modelLabelView.text = @"sometext";
if(cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:
@"transportTableCell" owner: self ////options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
单击表视图进行导航的代码:
- (IBAction)searchButtonClick:(id)sender {
CNJSONParser *parser = [[CNJSONParser alloc]init];
NSString *url = [parser getURL:@"43" :@"66"];
CNCarListWindowController *cars = [[CNCarListWindowController alloc]init];
cars.transportArray = [parser parseJSON:url];
[self.navigationController pushViewController:cars animated:TRUE];
}
只需如下更改代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"transportTableCell";
CNTransportCell *cell;
if(cell == nil){
cell = (CNTransportCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
return cell;
首先,您正在使用情节提要,而使用xib时将使用已实现的此方法。
在情节提要中,您需要在表格视图的“显示属性检查器”中提供标识符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.