AppDelegate无法添加子View

发布于 2024-12-29 21:41:28 字数 853 浏览 3 评论 0原文

由于 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 技术交流群。

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

发布评论

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

评论(1

喜爱皱眉﹌ 2025-01-05 21:41:28

它是 addSubview 而不是 addSubView:UIWindowUIView 的子类。

通常不建议将视图直接作为子视图添加到窗口,因此您应该尝试将视图作为子视图添加到顶部控制器视图。如果您有时间,您应该查看 查看编程指南视图控制器编程指南,以后会有用的。

It's addSubview not addSubView:. UIWindow is a subclass of UIView.

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.

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