Objective C 和 viewWillAppear 消息委托中的子类化?

发布于 2024-10-02 01:23:28 字数 775 浏览 0 评论 0原文

我可能会在这里感到困惑并提出错误的问题。

如果我在 appdelete.m 中使用像 UISplitViewController 这样的类,我收到的唯一消息是 UISplitViewController 调用的消息而不是任何 VIEW 消息吗?例如:

在 myappdelegate.h 中的 myappdelegate.m 中,

....
UISplitViewController *mySplitViewController = [[UISplitViewController alloc] init];

mySplitViewController.viewControllers = [NSArray arrayWithObjects:leftside,rightside,nil];
 ...

mySplitViewController.delegate = self;
....
[windows addSubView:mySplitViewController.view];
....
 -(void) viewWillAppear:(BOOL) animated {
 }

我包含了 UISplitViewControllerDelegate

我期望 viewWillAppear 会触发,但事实并非如此。我假设如果我有子类 UISplitViewControler 它就会着火。正确的?

顺便说一句:我这样做时没有使用 IB。我需要为 mySplitViewController 设置目标吗?

我想要做的是设置 splitviewcontroller 旋转时的方向。

I might be confused here and asking the wrong question.

If I use a class like the UISplitViewController inside the appdelete.m, will the only message i will receive is the message the UISplitViewController calls and not any VIEW message? for example:

in my myappdelegate.m

....
UISplitViewController *mySplitViewController = [[UISplitViewController alloc] init];

mySplitViewController.viewControllers = [NSArray arrayWithObjects:leftside,rightside,nil];
 ...

mySplitViewController.delegate = self;
....
[windows addSubView:mySplitViewController.view];
....
 -(void) viewWillAppear:(BOOL) animated {
 }

in myappdelegate.h I included UISplitViewControllerDelegate

I expected viewWillAppear to fire but it is not. I assume if I had subclass UISplitViewControler it would have fire. right?

BTW: I am doing this without using IB. Do I need to set the target for the mySplitViewController?

What I want to do is setup the orientation of the splitviewcontroller when it rotates.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

耀眼的星火 2024-10-09 01:23:28

viewWillAppear 方法和其他与视图相关的方法将在视图或视图控制器本身上调用,而不是在委托上调用。
这意味着,如果您将 UISplitViewController 的子类命名为 SplitViewControllerSubClass,则将在 实例上调用 view... 方法SplitViewControllerSubClass,不在委托对象上。
但是考虑到您正在创建视图并以编程方式显示它们,您已经确切地知道视图何时会出现(即,在将其添加到窗口之前),所以我相信您可以在此时进行任何您想要的设置。

the viewWillAppear method and other view related methods will be called on the view or view controller themselves, not on the delegate.
That means that if you make a subclass of UISplitViewController called SplitViewControllerSubClass, the view... methods will be called on the instance of SplitViewControllerSubClass, not on the delegate object.
But considering you are creating the views and displaying them programmatically, you already know exactly when the view will appear (i.e., right before you add it to the window), so I believe you could do whatever setup you want at that point.

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