R – Add a UIImageView as a subview of a UIViewController without using IB

cocoa-touchiphoneuiimageviewuiviewcontroller

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 // 🙂

Best Answer

stage = [Stage viewWithParent:self.view];

should work.

Is Xcode not giving you warnings about this?