AppDelegate can't add subView

2.6k views Asked by At

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. :)

1

There are 1 answers

6
alex-i On

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.