我有一个 UITableView 我已经分配了部分。将 didSelectRowAtIndex 与 indexPath.actually 一起使用时,NSIndexPath 参数不正确。例如,在第 1 行第 0 行,则 indexPath 为[0,1]; 第 2 行第 0 * 节,它得到 * [0, 2]。而第 0 行第 1 节对[0, 1]是正确的 。看来第 0 节是正确的。
我很沮丧,不知道为什么?谁能告诉我如何解决这个问题或给我一些建议?
以下是代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)sender
{
return _store.count;
}
- (NSInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSInteger)section {
if ([_store checkIfHasAdditionalContentInSection:section]) {
return ([_store additionalContentInSection:section].count + 1);
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CallLogCell";
CallLogCell *cell = [sender dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[[CallLogCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
CallLog *cLog = [_store itemAtIndex:indexPath];
cell.callTimes = [_store callTimesAtIndex:indexPath];
cell.callLog = cLog;
cell.index = indexPath.section;
[cell update];
return cell;
}
- (CGFloat)tableView:(UITableView*)sender heightForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell=[self tableView:sender cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DLog(@"indexPath %@", [indexPath description]);
**//I always get incorrect answer at here**
DLog(@"indexPath section %d row %d", indexPath.section, indexPath.row);
[sender deselectRowAtIndexPath:indexPath animated:NO];
}