好的,所以我是一个 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];
}
}