Objective C 和 viewWillAppear 消息委托中的子类化?
我可能会在这里感到困惑并提出错误的问题。
如果我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
calledSplitViewControllerSubClass
, theview...
methods will be called on the instance ofSplitViewControllerSubClass
, 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.