【发布时间】:2013-07-24 16:15:28
【问题描述】:
我有一个 UITableView 我已经分配了部分。将 didSelectRowAtIndex 与 indexPath.actually 一起使用时,NSIndexPath 参数不正确。 例如 在 section 1 row 0 中,则 indexPath 为 [0,1] ; section 2 row 0 *, 它得到 *[0, 2]。而 section 0 row 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];
}
【问题讨论】:
标签: tableview nsindexpath