当我更改详细视图时,我的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]);
}
编辑:当我在主视图控制器表视图中选择第一行以显示初始详细信息视图然后选择另一行以显示不同内容时,应用程序似乎崩溃。如果我在任何时候都没有选择第一行,那么一切正常。
答案 0 :(得分: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];
}