views:

773

answers:

2

In my UIViewController's viewDidLoad method I instance a UIImageView instance called stage:

stage = [Stage viewWithParent:self];

and that calls this:

- (id)initWithParent:(UIView *)parent {
    self = [self initWithFrame:CGRectZero];

    if (!self)
     return nil;

    [parent addSubview:self];

    return self;
}


+ (id) viewWithParent:(UIView *)parent {
    return [[[self alloc] initWithParent:parent] autorelease];
}

Before I used to call that from within a UIImageView and everything worked great. Images were visible, touch events were enabled and responded. From the UIViewController I get a window, but nothing shows up in it and no touches logged. What am I missing?

Any help appreciated!

Thanks // :)

+1  A: 

View controllers aren't views; they're controllers that control (own and manage) views. Try passing the view controller's view as the desired parent.

Peter Hosey
No joy there, didn't work. Thanks though.
Spanky
+1  A: 
stage = [Stage viewWithParent:self.view];

should work.

Is Xcode not giving you warnings about this?

mahboudz
No warnings, clean build with static analyzer turned on too. My code reads exactly what you have there, but still no joy. The App loads, rotates nicely to the right as intended, and shows me a white screen rather than my really groovy UIImageView subview...?
Spanky
you should still change self to self.view as you want the subview to be added to the view of the viewcontroller not the viewcontroller.If I change to [viewController addSubview:newView]; in my project, then Xcode gives me: /Users/mz/Dev/Working/BlurApp/Classes/BlurAppAppDelegate.m:22: warning: 'BlurAppViewController' may not respond to '-addSubview:'Since you're not seeing it, maybe your viewcontroller is defined as a UIView *?
mahboudz