替换详细视图控制器不会导致调用 viewWillAppear

发布于 2024-09-07 11:13:58 字数 750 浏览 2 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2024-09-14 11:13:58

不太确定您在这里要做什么,但简单地初始化 splitview 控制器并向其添加控制器不会强制显示视图。您必须将 splitview 控制器的视图添加到窗口中。

以下是 Xcode Splitview 模板的应用程序委托的 applicationDidFinishLaunching: 中的代码。

splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
splitViewController.delegate = detailViewController;

NSLog(@"master=%@",splitViewController.viewControllers);
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];

导航控制器中的视图之所以出现,是因为它已经附加到窗口并显示其受控控制器之一的视图。

编辑:

来自评论:

引用你的所有初始化代码
这里已经执行了。现在,让我们
假设左边有一张桌子
控制器,然后他选择另一行
那里,并且想要替换正确的
与另一个控制器。
splitViewController.view 添加在
窗口 фдкуфвн,因为一些 GUI
在viewDidLoad中初始化的元素,
正确呈现在视图中

你的问题出现是因为 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:

splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
splitViewController.delegate = detailViewController;

NSLog(@"master=%@",splitViewController.viewControllers);
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];

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:

All initialization code you are quoted
here is already performed. Now, let's
assume one have a table on the left
controller, then he select another row
there, and want to replace right
controller with another one.
splitViewController.view is added on
the window фдкуфвн, because some GUI
elements initialized in viewDidLoad,
are properly presented on view

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文