【问题标题】:indexPath null in didSelectRowAtIndexPath in an ipad splitview navigation appipad 拆分视图导航应用程序中 didSelectRowAtIndexPath 上的 indexPath null
【发布时间】:2011-03-01 15:04:48
【问题描述】:

我正在将一个相当简单的基于 iPhone 导航的应用程序移植到一个拆分视图 iPad 应用程序。
我在主视图上有两个嵌套的导航级别。用户从第一个表中选择一个值并加载第二个表。在第二个表上选择一个值会加载详细视图的详细信息项。或者它应该是。我的第二个控制器上的 didSelectRowAtIndexPath 正在触发,但 indexPath 为空。

我非常密切地关注 SplitView 模板。通过添加第二个 TableViewController,我才真正摆脱了人迹罕至的地方。我的 RootViewController 在 didSelectRowAtIndexPath 上加载了第二个 TableViewController,并且该部分正在工作。在我的第二个 TableViewController.m 中,我试图为 DetailView 设置详细信息项。但是没有给我行的是 didSelectRowAtIndexPath 方法。我对此很陌生,但对我来说,单击一行的方法会触发但没有该行的索引,这似乎很奇怪。

代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    TrackerSplitViewAppDelegate *appDelegate = (TrackerSplitViewAppDelegate *)[[UIApplication sharedApplication] delegate];
    detailViewController.thisRequest = [appDelegate.requests objectAtIndex:indexPath.row];
    NSLog(@"Request Loaded: %@", detailViewController.thisRequest.Title);
    NSLog(@"Index Row: %@", indexPath.row);
    [appDelegate release];

}

请求数组正在正确加载(appDelegate.requests),但我的 objectAtIndex 失败,因为 indexPath 为空。或者至少 indexPath.row 为空。

编辑:好的,下面的 cmets 是正确的,我没有正确使用 NSLog。 indexPath.row 很好(我认为它在调试器中使用鼠标悬停也显示为 null,但我只是不知道如何正确使用调试器)。

detailViewController 属性由于某种原因未正确设置。如果我用这个代替:

//detailViewController.thisRequest = [appDelegate.requests objectAtIndex:indexPath.row];
Request *aRequest = [appDelegate.requests objectAtIndex:indexPath.row];

aRequest 对象加载得很好。所以下一个问题是为什么在 detailViewController 对象上设置我的属性不起作用。对于这种环境中的事物如何持续存在,我仍然很模糊。任何额外的输入都会很棒。

【问题讨论】:

    标签: objective-c ios ipad didselectrowatindexpath


    【解决方案1】:

    indexPath.row 的值不是字符串。您无法使用%@ 记录它。尝试使用%i 或%li,它们用于整数。此外,您还没有真正正确地检查要加载的请求,afaik。 title 属性是否仅在加载成功后可用?

    【讨论】:

      【解决方案2】:

      NSLog(@"索引行:%@", indexPath.row);

      indexPath 是一个 NSIndexPath 对象,你可以使用 %@ 来打印它。
      但是 indexPath.row 和 indexPath.section 是 NSUInteger。所以你必须使用 %u 来打印它们。

      所以也许你的 indexpath.row 不是 nil(在没有对象中)而是 0(在零中,即一之前的数字)


      选择不是第一行的行,您应该会崩溃。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-24
        相关资源
        最近更新 更多