AppDelegate无法添加子View
由于 appDelegate 没有视图,只有窗口,因此很难弄清楚如何从中加载视图。我的问题长期以来一直是,当 didReceiveLocalNotification 触发时,我无法使用该事件加载新视图。我一直在努力解决这个问题,直到我必须对此做点什么。当我尝试 addSubview 时,xcode 给出错误:
Receiver tupe 'UIWindow' 例如消息未声明带有选择器 'addSubView' 的方法
:(at [self.window addSubView:view];)
screwLightBulbViewController *view = [screwLightBulbViewController newMyView];
[self.window addSubView:view];
我明白 appDelegate文件没有 addSubview 但我想在它触发时切换到特定视图。
我尝试了许多其他方法,例如调用 ScrewLightBulbViewController 中的函数并从中创建视图。我在 viewController 中的函数现在看起来像这样:
+(id)newMyView
{
UINib *nib = [UINib nibWithNibName:@"MyView" bundle:nil];
NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
screwLightBulbViewController *me = [nibArray objectAtIndex: 0];
return me;
}
任何方式的帮助都将非常感激,并感谢您的时间。 :)
Since appDelegate does not have a view, just window, its hard to figure out how to load a view from it. My problem has for long been that when didReceiveLocalNotification fires i cant load a new view with that event. I have been working around it til the point that i must do something about it. When i tries to addSubview, xcode gives me the error:
Receiver tupe 'UIWindow' for instance messages does not declare a method with selector 'addSubView'
for this: (at [self.window addSubView:view];)
screwLightBulbViewController *view = [screwLightBulbViewController newMyView];
[self.window addSubView:view];
I understand that the appDelegate file does'nt have a addSubview but i want to switch to a particular view when it fires.
I have tried many other ways, like calling a function in screwLightBulbViewController and make a view from that. My function in the viewController now looks like this:
+(id)newMyView
{
UINib *nib = [UINib nibWithNibName:@"MyView" bundle:nil];
NSArray *nibArray = [nib instantiateWithOwner:self options:nil];
screwLightBulbViewController *me = [nibArray objectAtIndex: 0];
return me;
}
any help in any way would be realy appreciated and thanks for you time. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是
addSubview
而不是addSubView:
。UIWindow
是UIView
的子类。通常不建议将视图直接作为子视图添加到窗口,因此您应该尝试将视图作为子视图添加到顶部控制器视图。如果您有时间,您应该查看 查看编程指南 和 视图控制器编程指南,以后会有用的。
It's
addSubview
notaddSubView:
.UIWindow
is a subclass ofUIView
.Adding a view directly as a subview to the window is not usually recommended, so instead you should try and add the view as a subview to the top controller view. If you can spare some time you should look over the view programming guide and view controller programming guide, it will be useful in the future.