好的,我是一个Master Detail应用程序,当用户点击一个单元格时,它会在DetailViewController中加载一个网页。问题是,在iPhone版本(这是一个通用应用程序)上,我必须单击单元格,然后返回到MasterViewController,然后再次单击该单元格以加载网页。我只需要这样做一次,我认为这就像是第一次启动网页或其他内容。虽然在iPad版本上,它第一次加载它。怎么了?
这是我的applicationDidFinishLaunching AppDelegate.m文件的代码,我在其中初始化DetailViewController
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
masterViewController.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPhone" bundle:nil];
} else {
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
self.window.rootViewController = self.splitViewController;
}
这里是didSelectCellAtIndexPath
的代码- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *object = _objects[indexPath.row];
NSURL *ex = [NSURL URLWithString:[object objectForKey:@"url"]];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.detailViewController.detailItem = object;
[self.detailViewController loadURL:ex];
self.detailViewController.detailItem = object;
[self.detailViewController loadURL:ex];
[self.navigationController pushViewController:self.detailViewController animated:YES];
} else {
self.detailViewController.detailItem = object;
[self.detailViewController loadURL:ex];
}
}
答案 0 :(得分:1)
在iPad上,您在分割视图控制器中有2个控制器,因此它们会被实例化,并在应用启动时加载它们的视图。在iPhone上,第二个控制器被实例化,但是在你推动它之前它的视图是不加载的 - 我认为这是不同的。您应该尝试将detailController方法loadURL:移动到它的viewDidAppear方法,而不是将它放在主控制器的didSelectRowAtIndexPath方法中。