在我的应用程序中,我正在使用UITableview。 在didselectrow委托方法中,如果我执行任何操作,则不会发生任何事情。
例如,我在表视图中有3行:
如果我选择第1行(indexPath.row==0),则不会发生任何事情。
如果再次选择第2行(indexPath.row==1),现在它会在控制台上记录上一个值,即indexPath.row==0。
如果再次选择第1行,则会记录其上一个值,即indexPath.row=1。
为什么会出现这种情况?
例如,我在表视图中有3行:
如果我选择第1行(indexPath.row==0),则不会发生任何事情。
如果再次选择第2行(indexPath.row==1),现在它会在控制台上记录上一个值,即indexPath.row==0。
如果再次选择第1行,则会记录其上一个值,即indexPath.row=1。
为什么会出现这种情况?
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomerInfoViewController *customer = [[EquipmentViewController alloc]initWithNibName:@"CustomerInfoViewController" bundle:nil];
EquipmentViewController *equpment = [[EquipmentViewController alloc]initWithNibName:@"EquipmentViewController" bundle:nil];
ContactsViewController *contacts = [[ContactsViewController alloc]initWithNibName:@"ContactsViewController" bundle:nil];
if(indexPath.row == 0)
{
NSLog(@"one %d",indexPath.row);
[detailsView addSubview:customer.view];
}
if(indexPath.row == 1)
{
NSLog(@"two %d",indexPath.row);
[detailsView addSubview:equpment.view];
}
if(indexPath.row == 2)
{
NSLog(@"three%d",indexPath.row);
[detailsView addSubview:contacts.view];
}
}
请有人帮帮我。
提前感谢。
NSLog(@"%d %d", indexPath.row, indexPath.section);
来查看函数是否未被调用或者您的代码是否有误。您需要清除一些选项以更好地理解问题。 - DAS