替换详细视图控制器不会导致调用 viewWillAppear
我正在将 iPhone 应用程序移植到 iPad。在iPhone上,我选择表中的行,然后下一个视图控制器被推送到navigationController的顶部(现在导航在分割视图控制器的左侧部分执行)。对于iPad,我这样修改了代码:
if (deviceIsIPad())
{
UISplitViewController *svc = (UISplitViewController *)[self findNearestParentOfClass:[UISplitViewController class]];
svc.viewControllers = [NSArray arrayWithObjects:[svc.viewControllers objectAtIndex:0],
nextViewController,
nil];
}
else
[self.navigationController pushViewController:nextViewController animated:YES];
iPhone代码没有问题(当控制器被推送到导航控制器时),但在iPad上viewWillAppear:不被调用(但是调用viewDidLoad),而我有理由执行一些自定义就在视图中将出现:。为什么它没有被调用,我应该怎么做才能强制调用它?
非常感谢!
I'm porting my iPhone app to iPad. On iPhone I select row in the table, and after that the next view controller is pushed to the top of navigationController (now navigation is performed on the left part of split view controller). For iPad i modified the code this way:
if (deviceIsIPad())
{
UISplitViewController *svc = (UISplitViewController *)[self findNearestParentOfClass:[UISplitViewController class]];
svc.viewControllers = [NSArray arrayWithObjects:[svc.viewControllers objectAtIndex:0],
nextViewController,
nil];
}
else
[self.navigationController pushViewController:nextViewController animated:YES];
There are no problem at iPhone code (when controller is pushed to navigation controller), but on iPad viewWillAppear: is not called (viewDidLoad is called however), while I have a reason to perform some customization right in viewWillAppear:. Why is it not called, and what should I do to force it to be called?
Much thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定您在这里要做什么,但简单地初始化 splitview 控制器并向其添加控制器不会强制显示视图。您必须将 splitview 控制器的视图添加到窗口中。
以下是 Xcode Splitview 模板的应用程序委托的
applicationDidFinishLaunching:
中的代码。导航控制器中的视图之所以出现,是因为它已经附加到窗口并显示其受控控制器之一的视图。
编辑:
来自评论:
你的问题出现是因为 splitview 控制器的详细(右侧)视图始终可见,即它仅在第一次加载后立即调用
viewWillAppear
出现。细节方面没有任何一点是没有视图的。我不确定完全交换 splitview 的 viewControllers 会做什么。如果您想即时更改详细视图。您需要将导航控制器放在右侧,然后在该导航中推送和弹出视图控制器以响应右侧控制器中的事件。
了解 iPad iPod 应用程序的工作原理。您可以看到播放列表的左侧视图,右侧是播放列表中所有歌曲的列表。选择歌曲会将歌曲详细信息视图推送到歌曲列表顶部。
Not exactly sure what you're trying to do here but simply initializing a splitview controller and adding controllers to it does not force views to appear. You have to add the splitview controller's views to the window.
Here is the code from the Xcode Splitview template's app delegate's
applicationDidFinishLaunching:
The views in the navigation controller appear because it is already attached to the window and displaying the view of one of its controlled controllers.
Edit:
From Comments:
It sounds like your problem arises because the detail (right-side) view of a splitview controller is always visible i.e. it only appears i.e calls
viewWillAppear
, once immediately after first being loaded. There is no point at which the detail side has no view present. I'm not sure what entirely swapping out viewControllers of the splitview will do.If you want to change the detail view on the fly. You need to put a navigation controller in the right side and then push and pop view-controllers in that nav in response to events in the right side controller.
Look at how the iPad iPod app works. You have a leftside view of playlist and on the right side, a list of all the songs in the playlist. Selecting a song pushes a song detail view on top the list of songs.