iOS 7:
Exception Detail: *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2935.137/UITableView.m:6509
代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, UISIZE.width, UISIZE.height -64) style:UITableViewStylePlain];
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([GWVipRechargeCell class]) bundle:nil] forCellReuseIdentifier:@"GWVipRechargeCell"];
[self.view addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
GWVipRechargeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"GWVipRechargeCell"];
if (cell == nil) {
cell = [tableView dequeueReusableCellWithIdentifier:@"GWVipRechargeCell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
我在self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
一些tabelview:
self.tabelView.dataSource = self;
self.tabelView.delegate = self;
self.tabelView.tableFooterView = [[UIView alloc] init];
self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
我尝试了iOS 5 Storyboard Custom Cell Crash: UITableView dataSource must return a cell的所有答案,但它仍然在self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
解决方案:
我移动设置顺序
self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tabelView.tableFooterView = [[UIView alloc] init];
它运行成功!我也很困惑!!!
如果我设置tableHeaderView也有这个问题
答案 0 :(得分:1)
[self.YOURTABLEVIEW registerNib:[UINib nibWithNibName:@"YOURCUSTOMCELL" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"YOURCUSTOMCELL_IDENTIFIER"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YOURTABLEVIEWCELL_CLASS *cell = [tableView dequeueReusableCellWithIdentifier:@"YOURTABLEVIEWCELL_IDENTIFIER"];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"YOURTABLEVIEWCELL_IDENTIFIER" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
// here write your cell coding like give value to your lable, image , etc.
return cell;
}
答案 1 :(得分:1)
试试这个 -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
GWVipRechargeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GWVipRechargeCell"];
if (!cell) {
// if cell is empty create the cell
cell = [[GWVipRechargeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GWVipRechargeCell"];
}
return cell;
}
答案 2 :(得分:0)
在设置tableHeaderView或tableFooterView之前设置tableView其他属性,如下所示:
// set tableView's other properties
tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
// set tableHeaderView or tableFooterView after set tableView's other properties
tabelView.tableHeaderView = headView;
tabelView.tableFooterView = footerView;