在AppDelegate
我们创建DetailView
,然后在其上方显示loginView
(UIModalPresentationFullScreen
)。登录后,loginView
被解雇。
DetailView
有一个tableView
,当您选择一个单元格/行时,第二个detailView
被推送。
到目前为止我做了什么:
在AppDelegate
我要求UI_USER_INTERFACE_IDIOM()
,当成语为iPad
时,我创建了splitView
:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
FirstDetailViewController* fdvc = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailViewController" bundle:nil];
SecondDetailViewController* sdvc = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailViewController" bundle:nil];
UINavigationController* fdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:fdvc];
UINavigationController* sdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:sdvc];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:fdvcNavigationController, sdvcNavigationController, nil];
登录后,我的 LoginView 被解雇,我的 UISplitViewController 显示,左侧是第一个DetailView
(主)。所以一切都很好。
现在我转到 FirstDetailViewController.m 并搜索 didSelectRowAtIndexPath ,因为我在“iPhone版本”中找到了pushView到 SecondDetailViewController ”
这就是我被困的地方。我已经尝试了几个SplitView
教程,并阅读了其他有关splitview
的问题。
但我认为我的问题是某种“基本”,因为我一般都是编程/ iOS的新手,并且不知道我的所有工具。
任何帮助都将不胜感激。
答案 0 :(得分:3)
当使用表格视图和表格中的项目的其他类型的“显示”视图编写应用程序时,我这样做是因为它适用于两个设备:
// In App Delegate...
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create views
MyTableViewController* myTable = [[MyTableViewController alloc] init];
MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
UINavigationController* tableNav = [[UINavigationController alloc] initWithRootViewController:myTable];
UINavigationController* detailNav = [[UINavigationController alloc] initWithRootViewController:myDetail];
// Check device type
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Use a split view
UISplitViewController* splitView = [[UISplitViewController alloc] init];
split.viewControllers = @[tableNav, detailNav];
self.window.rootViewController = split;
} else {
// Use a single view for iPhone
self.window.rootViewController = tableNav;
}
}
// In table view
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Check device type
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Tell the already visible detail view to load something
MyData* data = ...; \\ Get your thing to display however you want
[[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayMyData" object:data];
} else {
// No detail controller exists yet, so create it
MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
[self.navigationController pushViewController:myDetail animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:@"DisplayMyData" object:data];
}
}
// In detail view
-(void) viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayData:) name:@"DisplayMyData" object:nil];
}
-(void) displayData:(NSNotification*)notify {
MyData* data = (MyData*) notify.object;
... // Display however...
}