【问题标题】:UITableview - tableView:didDeselectRowAtIndexPath: method not working properly?UITableview - tableView:didDeselectRowAtIndexPath: 方法不能正常工作?
【发布时间】:2011-12-30 19:31:21
【问题描述】:

在我的应用程序中,我使用的是 UITableview。在那个委托方法中,如果我做了任何操作就不会发生。

例如,我在 tableview 中有 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];
    }
}

请任何人帮助我。

提前致谢。

【问题讨论】:

  • 显示一些实际代码可能是什么?
  • 似乎在逻辑上是正确的。也许将初始化拉入 if 语句。会不会和这些部分有关?也许做NSLog(@"%d %d", indexPath.row, indexPath.section); 看看函数是否没有被调用或者你的代码是错误的。您必须清除一些选项才能更好地理解问题。

标签: iphone uitableview


【解决方案1】:

您已经实现了didDeselectRowAtIndexPath 方法,而不是预期的didSelectRowAtIndexPath

【讨论】:

  • didSelectRowAtIndexPath: 以前默认添加到 UITableViewController 类,但现在它被 prepareForSegue: 取代,烦人。这也意味着很多人没有注意到方法名称中的小De,而使用了错误的方法。
【解决方案2】:

Vladimir 说的方法实现错误。使用 didSelectRowAtIndexPath

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 2021-09-14
    • 1970-01-01
    相关资源
    最近更新 更多