Search code examples
objective-cxcode4

Why won't this code allocate a subView?


This is my code where I'm trying to create a subView... I'm using XCode4 with StoryBoards. The app is crashing on the 2nd line where it is allocating subView with EXC_BAD_ACCESS. vFrame has valid content. What is wrong with this? (I'm using XCode4 with Storyboards, btw).

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect vFrame = CGRectMake(60,100,200,200);
    subView = [[UIView alloc] initWithFrame:vFrame];
    subView.backgroundColor = [UIColor redColor];
    [self.view addSubview: subView];
}

UPDATE: definition for subView:

@interface PreferencesViewController : UIViewController  {

    UIView *subView;
}

@property (nonatomic, retain)  UIView *subView;

@end

Solution

  • The problem was the UIViewController was farkled...don't know how, but once it was replaced, it worked like a champ! Thank you all for your responses...