【发布时间】:2010-08-07 00:29:31
【问题描述】:
我遇到问题的表格是从另一个表格控制器推送的,并且该表格中只有一个部分,并且我正在使用自定义单元格。这是 numberOfRowsInSection 的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger numberOfRows;
if ([imagesArray count] == 0) {
numberOfRows = 0;
}
else {
if ([imagesArray count] % 4 == 0) {
numberOfRows = [imagesArray count] / 4;
}
else {
numberOfRows = ([imagesArray count] / 4) + 1;
}
}
NSLog(@"numberOfRowsInSection: %d", numberOfRows);
return numberOfRows;
}
这里的日志总是打印预期的行数。到现在为止还挺好。现在让我们看一下 cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath: %@", [indexPath description]);
ImageTableCell *cell = (ImageTableCell *)[tableView dequeueReusableCellWithIdentifier:@"4ImagesCell"];
if (cell == nil) {
cell = [[[ImageTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"4ImagesCell"] autorelease];
}
return cell;
}
这里的控制台“总是”打印以下内容:
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 0]
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 1]
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 2]
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 3]
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 4]
无论 numberOfRowsInSection 返回的值是什么,无论是零还是 100,表格总是要求 5 行!我什至尝试在 numberOfRowsInSection 中返回一个静态数字而不是当前条件,但这对实际的单元格数量没有影响!
让我抓狂的是,表格在进入 cellForRowAtIndexPath 之前确实达到了 numberOfRowsInSection 方法!
我唯一能想到的可能是这个表控制器是从另一个 UITableViewController 推送的,但是我在这个表中时从不检查前一个表的 numberOfRowsInSection 方法,我什至尝试修改父表中的行没有任何运气。
如果缺少任何类型的信息,请告诉我。这个项目很复杂,我想不出任何其他相关信息来解决这个问题。
【问题讨论】:
标签: iphone objective-c uitableview uitabbarcontroller