0

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 Answers1

2

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.

alex-i
  • 5,406
  • 2
  • 36
  • 56
  • OMG! Well.. Sometimes it's easyer than other times. Thanks! So i should go for [self.window.view addSubview:view];? Thanks for your links too. :) – Kristoffer Frisell Jarnevid Jan 29 '12 at 12:06
  • `[self.window addSubview:view]`, `UIWindow` doesn't have any `view` property. You're welcome. – alex-i Jan 29 '12 at 12:11
  • With your change i corrected the error. My problem is not fully solved, even after reading the content of your links provided. What does '__strong' mean. Should i make it weak? :p the full warning: Incompatible pointer types sending 'screwLightBulbViewController' * __strong' to parameter of type 'UIView *' – Kristoffer Frisell Jarnevid Jan 29 '12 at 12:23
  • So you mean that its not possible to solve my problem? When the didReceiveLocalNotification fires i cant control any view related elements? Do you have any sugestions how to solve my problem? – Kristoffer Frisell Jarnevid Jan 29 '12 at 12:35
  • I have been playing around with trying this all day. It seems that how much i try, it will never change anything to the current view. The problem is that if i call an other method in another class, the self keyword points to the AppDelegate-file witch does'nt have a view. Therefore i can't interact with any view. Have i got it right? There is no way to make this work. Right? – Kristoffer Frisell Jarnevid Jan 29 '12 at 16:32
  • You can create some methods/properties in the AppDelegate to return any view (or viewcontroller) you are using in the application, as long as your view(controllers) structure is well defined (e.g if you have a navigation based app, use the `UINavigationBar` methods to get the top view controler; if you have tab based application use the `UITabBarController` methods to get the top (visible) view controller or any other view controllers you wish to access. – alex-i Jan 30 '12 at 07:53