Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在自定义单元格的标签中指定值时发生异常_Iphone - Fatal编程技术网

Iphone 在自定义单元格的标签中指定值时发生异常

Iphone 在自定义单元格的标签中指定值时发生异常,iphone,Iphone,我有一个从不同nib加载自定义单元格的表视图,我遇到异常: 2011-05-18 18:01:00.323 custInfoService[4370:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709 2011-05-18 18:01:00.324 custInf

我有一个从不同nib加载自定义单元格的表视图,我遇到异常:

2011-05-18 18:01:00.323 custInfoService[4370:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709 2011-05-18 18:01:00.324 custInfoService[4370:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 2011-05-18 18:01:00.325 custInfoService[4370:20b] Stack: ( 11125851, 2442997307, 2011-05-18 18:01:00.323 custInfoService[4370:20b]***在-[UITableView\u createPreparedCellForGlobalRow:withIndexPath:],/SourceCache/UIKit/UIKit-984.38/UITableView.m:4709中断言失败 2011-05-18 18:01:00.324 custInfoService[4370:20b]***由于未捕获的异常“nSinternalinconsistenceException”而终止应用程序,原因:“UITableView数据源必须从tableView返回单元格:cellForRowAtIndexPath:” 2011-05-18 18:01:00.325客户信息服务[4370:20b]堆栈:( 11125851, 2442997307, 当我使用断点时,我知道异常是在开关的情况下。我不知道为什么它会出现异常??帮帮我! 这是我的密码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"BookDetailViewController" owner:self options:NULL]; cell = nibloadedcell; } tbcel.layer.cornerRadius = 10; tbcel.text = aBook.Name; UILabel *fieldlabel = (UILabel *) [cell viewWithTag:1]; fieldlabel.text = [fieldarray objectAtIndex:(indexPath.row)]; UILabel *valuelabel = (UILabel *) [cell viewWithTag:2]; switch(indexPath.section) { case 0: valuelabel.text = aBook.Address; break; case 1: valuelabel.text = aBook.Phone; break; case 2: valuelabel.text = aBook.Purchase; } return cell; } -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{ 静态NSString*CellIdentifier=@“Cell”; UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 如果(单元格==nil) { [[NSBundle mainBundle]loadNibNamed:@“BookDetailViewController”所有者:自选项:NULL]; cell=nibloaddedcell; } tbcel.layer.cornerRadius=10; tbcel.text=aBook.Name; UILabel*字段标签=(UILabel*)[带标记的单元格视图:1]; fieldlabel.text=[fieldarray objectAtIndex:(indexath.row)]; UILabel*valuelabel=(UILabel*)[带标记的单元格视图:2]; 开关(indexPath.section) { 案例0: valuelabel.text=aBook.Address; 打破 案例1: valuelabel.text=aBook.Phone; 打破 案例2: valuelabel.text=aBook.Purchase; } 返回单元; }
所以最明显的问题是

[[NSBundle mainBundle] loadNibNamed:@"BookDetailViewController" owner:self options:NULL];
cell = nibloadedcell;
未设置您的
nibloaddedcell
出口,因此
cell
始终是
nil
。因此没有返回有效的单元格,并且您得到错误
UITableView数据源必须从tableView:cellforrowatinexpath:
返回单元格


别忘了,发送到
nil
的消息会被悄悄忽略-如果单元格为
nil
,则函数的其余部分可以正常执行,并且什么也不做!

谢谢…我犯了一个愚蠢的错误:)nib名称是“bookdetailviewcontrollercell”我使用的是我写的上面的内容。@user720235:如果他的答案解决了你的问题,你应该把它标记为已回答,这样他就可以获得学分,其他人也可以看到。