如何在使用 splitViewController 的 iPad 上引用detailViewController
我在 XCode 4.3 和 IOS 5 上设置了一个项目,没有使用 iPhone 和 iPad 的情节提要,使用创建新项目对话框中的默认主/细节设置。
iPhone端运行得很好。我在 tableView 中选择一个选项,detailViewController 屏幕会根据选择更新新信息。
我的 didSelectRowAtIndexPath 实现是:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Shapes *currentShape = [self.shapesArray objectAtIndex:indexPath.row];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (!self.detailViewController) {
self.detailViewController = [[[GeoDetailViewController alloc] initWithNibName:@"GeoDetailViewController_iPhone" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
[self.detailViewController populateDisplay:currentShape];
} else {
[self.detailViewController populateDisplay:currentShape];
}
}
但是,当我在 iPad 上运行时, self.detailViewController 不存在。所以显示不会更新。我仍然可以在 iPad 屏幕上看到它,但我无法更改上面的任何内容。如何在代码中引用它以便可以更改显示的内容?
I setup a project on XCode 4.3 and IOS 5 without using storyboards for both iPhone and iPad using the default Master/Detail setup from the create new project dialog.
The iPhone side works just fine. I select an option in the tableView and the detailViewController screen updates with the new information based on the selection.
My implementation of didSelectRowAtIndexPath is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Shapes *currentShape = [self.shapesArray objectAtIndex:indexPath.row];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (!self.detailViewController) {
self.detailViewController = [[[GeoDetailViewController alloc] initWithNibName:@"GeoDetailViewController_iPhone" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
[self.detailViewController populateDisplay:currentShape];
} else {
[self.detailViewController populateDisplay:currentShape];
}
}
However, when I run on the iPad, self.detailViewController does not exist. so the display doesn't update. I can still see it on the iPad screen, I just can't change anything on it. How do I reference it in the code so I can make changes to what is displayed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对主视图/详细视图的模板实现感到困惑。我问了类似的问题:
如何使用 MasterDetail 应用程序模板更新 DetailView
您可以使用为DetailViewController 类默认设置的detailItem(id - 这样您可以传入引用)属性。
I was puzzled by the templates implementation of the Master/Detail view. I asked a similar question:
How to update DetailView using MasterDetail Application Template
You can use the detailItem (id - so you can pass in a reference) property that is set up by default for the DetailViewController class.
如果您有指向拆分视图控制器本身的指针,您可以执行以下操作:
要获取指向拆分视图的指针,您可能必须通过应用程序委托:(
假设您正在使用默认的拆分视图控制器模板 - YMMV取决于您的实现方式)
请注意,当您创建分割视图时,您必须将详细信息视图控制器设置为
GeoDetailViewController
- 如果您不是并且不能出于应用程序设计的原因,我可以编辑我的工作答案围绕那个。If you have a pointer to the split view controller itself, you can do:
To get the pointer to your split view, you will probably have to go via your app delegate:
(assuming that you are using the default split view controller template - YMMV depending on how you have implemented it)
Note that when you create your split view, you must set the detail view controller to be a
GeoDetailViewController
- if you are not and you cannot for app design reasons, I can edit my answer to work around that.在 master/detail 模板中,Apple 在 MasterViewController 中使用以下代码(即左侧的代码):
MasterViewController 上的属性定义为:
In the master/detail template, Apple uses the following code in the MasterViewController (i.e. the one on the left):
With the property on MasterViewController defined as: