我正在开发一个iPhone应用程序,其中有一个UITableView,它正在通过URL填充XML feed。UITableView没有正确选择
举例说,三个单元格被填充。
如果我点击第一个单元格没有任何反应,但是如果我点击第二个或第三个单元格,它将把我带到与第一个单元格相关的第二个屏幕,并且与其他单元格相同 - ,点击另一个,它会将我带到上一个选中的第二个屏幕。
我从来没有发生过这种情况,而且相当困惑。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"UITableViewCell"];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[atm atmName]];
float distance = [[atm atmDistance] floatValue];
NSString *distanceString = [NSString stringWithFormat:@"%0.2f miles from current location", distance];
[[cell detailTextLabel] setText:distanceString];
return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]];
ATMDetailsController *detailsController = [[ATMDetailsController alloc] init];
[detailsController setCurrentATM: atm];
[[self navigationController] pushViewController:detailsController animated:YES];
}
感谢, 尼克
任何示例代码? – TigerCoding 2012-02-11 20:08:08
请发布您的cellForRowAtIndexPath:代码 – Rayfleck 2012-02-11 20:10:29
听起来像您在'tableView:didSelectRowAtIndexPath:'中的索引是关闭的,但没有看到一些相关的代码,这是不可能的。 – 2012-02-11 20:11:34