xcode -[UITableView _configureCellForDisplay:forIndexPath:] 中的断言失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15994216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
提问by evana_margain
Can anybody tell me why am I getting this error?
谁能告诉我为什么我会收到这个错误?
Here's my .m file:
这是我的 .m 文件:
#import "ListaParticipantesViewController.h"
#import "Participantes.h"
#import "ModParticipantesViewController.h"
@implementation ListaParticipantesViewController
@synthesize dao;
@synthesize participantes;
- (void)viewDidLoad
{
dao = [[ParticipantesDAO alloc] init];
participantes = [[NSMutableArray alloc] init];
participantes = [dao getDatos];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [participantes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"celda";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [[participantes objectAtIndex:[indexPath row]] valueForKey:@"nombre"];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ModParticipantesViewController *destino = [self.storyboard instantiateViewControllerWithIdentifier:@"visualizacion"];
Participantes *tmp = [participantes objectAtIndex:[indexPath row]];
destino.participante = tmp;
[self.navigationController pushViewController:destino animated:YES];
}
@end
and the error displayed is:
并且显示的错误是:
2013-04-13 17:40:20.235 Registro[5314:c07] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471
2013-04-13 17:40:20.237 Registro[5314:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x209d012 0x11aae7e 0x209ce78 0xc40665 0x1a4c1b 0x13940c 0x1a4a7b 0x1a9919 0x1a99cf 0x1921bb 0x1a2b4b 0x13f2dd 0x11be6b0 0x2699fc0 0x268e33c 0x2699eaf 0x1de2bd 0x126b56 0x12566f 0x125589 0x1247e4 0x12461e 0x1253d9 0x1282d2 0x1d299c 0x11f574 0x11f76f 0x11f905 0x128917 0xec96c 0xed94b 0xfecb5 0xffbeb 0xf1698 0x1ff8df9 0x1ff8ad0 0x2012bf5 0x2012962 0x2043bb6 0x2042f44 0x2042e1b 0xed17a 0xeeffc 0x306d 0x1ef5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Thanks in advance!
提前致谢!
回答by Hal Mueller
The storyboard or XIB does not have a cell defined with the cell identifier you specified.
故事板或 XIB 没有使用您指定的单元标识符定义的单元。
回答by Dipak Narigara
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return cell; // at the end of your method
}
回答by Solid Soft
You need to set delegate and datasource of tableview in header.
您需要在标题中设置 tableview 的委托和数据源。
Objecitve c
客体c
<UITableViewDataSource, UITableViewDelegate>
Swift
迅速
class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
}
}
回答by XHotSniperX
Have you subclassed your ListaParticipantesViewController with the classes UITableViewDelegate, UITableViewDataSource? They are needed to be able to use delegate and data source methods.
您是否将 ListaParticipantesViewController 子类化为 UITableViewDelegate、UITableViewDataSource 类?他们需要能够使用委托和数据源方法。
In Swift:
在斯威夫特:
class ListaParticipantesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
}
回答by Joel Balmer
I got the very same error. It turns out it was the same problem, that it couldn't find my cell identifier, but for a different reason - I was subclassing UITableViewCell, but hadn't registered my .XIB file with my UITableView for a reuseIdentifier.
我得到了同样的错误。事实证明这是同样的问题,它找不到我的单元格标识符,但出于不同的原因 - 我正在继承 UITableViewCell,但没有使用我的 UITableView 注册我的 .XIB 文件作为重用标识符。
I solved it by resgitering in the viewDidLoad
我通过在 viewDidLoad 中重新分配来解决它
- (void)viewDidLoad {
[super viewDidLoad];
//LOAD XIB
UINib *nib = [UINib nibWithNibName:@"NAME_OF_NIB_FILE"
bundle:nil];
//REGISTER XIB, CONTAINING THE CELL (IDENTIFIER NAME USUALLY SAME AS NIB NAME)
[[self tableView] registerNib:nib
forCellReuseIdentifier:@"IDENTIFIER_NAME"];
}
And then creating the cell
然后创建单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//GET THE RECYCLED CELL
TableCellSubclass *cell = [tableView dequeueReusableCellWithIdentifier:@"IDENTIFIER_NAME"];
//CONFIGURE THE CELL
return cell;
}
Hope this helps someone!
希望这对某人有帮助!
回答by jonypz
In my case I had a simple mistake..
就我而言,我有一个简单的错误..
My number of rows was defined by array.count.
我的行数由array.count 定义。
When I refreshed this array I was removing all the objects, initiating the connection, adding the objects to the array and then reloading the tableview.
当我刷新这个数组时,我正在删除所有对象,启动连接,将对象添加到数组,然后重新加载 tableview。
I put the objects removal once the connection was completed and it solved my issue.
连接完成后,我将对象移除并解决了我的问题。