我有两个自定义单元格。我想在我的显示器中显示2个部分UITableView
。第一部分,其中一行显示第一个自定义单元格,第二部分显示从核心数据中提取的对象列表。
我应该如何实现“ cellForRowAtIndexpath”方法?
这是我的一些代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (section == 0) {
return 1;
} else if (section == 1) {
//gastos is an array
return [self.gastos count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
case 0:
{
SaldoCelda *cell1 = [tableView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
return cell1;
}
case 1:
{
static NSString *CellIdentifier = @"Cell";
CeldaGasto *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSManagedObject *gasto = [self.gastos objectAtIndex:indexPath.row];
[cell.monto setText:[NSString stringWithFormat:@"%@ AR$", [gasto valueForKey:@"monto"]]];
[cell.categoria setText:[NSString stringWithFormat:@"%@", [gasto valueForKey:@"categoria"]]];
[cell.fecha setText:[NSString stringWithFormat:@"%@", [gasto valueForKey:@"fecha"]]];
return cell;
}
default:
break;
}
return 0;
}
这是我收到的错误消息:
/ [UITableView _configureCellForDisplay:forIndexPath:],/ SourceCache / UIKit_Sim / UIKit-2903.23 / UITableView.m:6246 2014-03-05 01:02:57.181支出[2897:70b] *断言失败,因为未捕获异常NSInternalInconsistencyException',原因:“ UITableView数据源必须从tableView:cellForRowAtIndexPath返回单元格:”
感谢您的帮助!
除了要返回nil
其中一个单元格之外,您还遇到了一个问题numberOfRowsInSection
,您正在为第1节!!返回0行,尽管您希望自己的这一节中有行cellForRowAtIndexPath
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句