iPad,主视图中的导航堆栈,在主视图中选择一个项目并更新详细信息视图
我正在构建我的第一个应用程序,并一直在寻找答案,但找不到答案。可能是我搜索时使用的关键字。所以这是我的问题。
这是一个带有主从模板的 iPad 应用程序 (Xcode 4)。主视图应该显示类别列表,选择每个类别后,文章列表将被推送到主视图(导航栏上有一个后退按钮可返回类别列表)。
我能够让它工作到这里。选择文章后,我似乎无法使用文章名称更新详细视图中的标签。
这是我在 AppDelegate.m 中的代码:
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
ArticlesViewController *articlesViewController = [[ArticlesViewController alloc] initWithNibName:@"ArticlesViewController" bundle:nil];
UINavigationController *articlesNavigationController = [[UINavigationController alloc] initWithRootViewController:articlesViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
articlesViewController.mainDetailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
如果我将以下行:更改
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
为
self.splitViewController.viewControllers = [NSArray arrayWithObjects:articlesNavigationController, detailNavigationController, nil];
标签将被更新。
有什么指点吗?我看过有关主视图连接到详细视图的教程,其中主视图只有一级导航,但似乎找不到模拟我的情况的教程。再说一遍,可能我只是不知道要搜索的正确关键字。
提前谢谢您。
I'm building my first app and have been searching around for answers but couldn't find an answer. May be it's the keywords I used in searching. So here is my problem.
This is an iPad app (Xcode 4) with master-detail template. The master view is supposed to show a list of categories, upon selecting each category, a list of articles will be pushed to the master view (with a back button on the navigation bar to go back to the category list).
I'm able to make it work up to here. After selecting an article, I can't seem to update the label in the detail view with the article name.
This are my codes in AppDelegate.m:
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
ArticlesViewController *articlesViewController = [[ArticlesViewController alloc] initWithNibName:@"ArticlesViewController" bundle:nil];
UINavigationController *articlesNavigationController = [[UINavigationController alloc] initWithRootViewController:articlesViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
articlesViewController.mainDetailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
If I change the following line:
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
to
self.splitViewController.viewControllers = [NSArray arrayWithObjects:articlesNavigationController, detailNavigationController, nil];
The label will be updated.
Any pointers? I have seen tutorials on master view connecting to detail view where the master view only have one level of navigation, but can't seem to find one that simulates my situation. Again, may be I just don't know the right keywords to search.
Thank you in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法使用 NSNotificationCentre 让它工作。
在 ArticlesViewController(在 MasterViewController 中选择类别时显示的第二层)中,我发布了本地通知。
在 DetailViewController 中,我为通知添加了一个观察者。
这样我就可以更新详细视图中的标签。
感谢这个精彩的视频教程:http://youtu.be/vnkNUoRtk1E
I managed to get it working by using NSNotificationCentre.
In ArticlesViewController (the second tier that is shown upon selecting a category in MasterViewController), I post a local notification.
In DetailViewController, I add an observer for the notification.
This way I can update the label in the detail view.
Credits go to this great video tutorial: http://youtu.be/vnkNUoRtk1E