1

当我更改详细视图时,我的 iPad 应用程序崩溃。我设置了一个异常断点来查明导致问题的代码行。它似乎偶尔发生,所以我不太确定发生了什么。有什么建议么?

例如,它在这一行崩溃:

self.splitViewController.viewControllers = details;

在我的主视图控制器中的 didSelectRowAtIndexPath 方法中

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        KFBDetailViewController *detailViewController = [[KFBDetailViewController alloc] initWithNibName:@"KFBDetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

        [details replaceObjectAtIndex:1 withObject:detailNavigationController];

        self.splitViewController.viewControllers = details;

        KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
        appDelegate.window.rootViewController = self.splitViewController;
    }

它也在另一个视图中做到了:

appDelegate.splitViewController.viewControllers = details;

这是那个的 didSelectRowAtIndexPath :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

    UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:webViewController];

    [details replaceObjectAtIndex:1 withObject:detailNav];

    KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];

    appDelegate.splitViewController.viewControllers = details;
    appDelegate.window.rootViewController = self.splitViewController;
    appDelegate.splitViewController.delegate = webViewController;

    [appDelegate.splitViewController viewWillAppear:YES];

    // Grab the selected item
    RSSItem *entry = [[channel items]objectAtIndex:[indexPath row]];

    NSLog(@"Channel Items: %@", [[channel items]objectAtIndex:[indexPath row]]);

    // Construct a URL with the link string of the item
    NSURL *url = [NSURL URLWithString:[entry link]];

    NSLog(@"Link: %@", [entry link]);

    // Construct a request object with that URL
    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    NSLog(@"URL: %@", url);

    // Load the request into the web view
    [[webViewController webView]loadRequest:req];
    webViewController.hackyURL = url;
    NSLog(@"Request: %@", req);

    // Set the title of the web view controller's navigation item
    [[webViewController navigationItem]setTitle:[entry title]];

    NSLog(@"Title: %@", [entry title]);
}

编辑:当我在主视图控制器表视图中选择第一行以显示初始详细视图然后选择另一行以显示不同的内容时,该应用程序似乎崩溃了。如果我在任何时候都不选择第一行,一切都会正常工作。

4

1 回答 1

1

我通过调整在主视图中点击第一行时显示初始详细视图的方式来解决问题。

您可以在我的原始帖子中看到原始实现。这是我如何改变它。

if (indexPath.row == 0)
    {
        KFBDetailViewController *detailViewController = [[KFBDetailViewController alloc]initWithNibName:@"KFBDetailViewController_iPad" bundle:nil];

        NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

        UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:detailViewController];

        [details replaceObjectAtIndex:1 withObject:detailNav];

        KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
        appDelegate.splitViewController.viewControllers = details;
        appDelegate.window.rootViewController = self.splitViewController;
        appDelegate.splitViewController.delegate = detailViewController;
        [appDelegate.splitViewController viewWillAppear:YES];
    }
于 2013-08-06T13:12:37.723 回答