I have a Storyboard View Controller (with my own custom sub class) of which I have a initWithCoder custom method, where I want to popular the view with my own custom objects (I want to maintain the flexibility of doing this programmatically.
Code works fine until [self.view addSubview:button]; is called, then it crashes with: “Could not load NIB in bundle”.
All I wanted to do was add a UIButton on my view…
- (id)initWithCoder:(NSCoder*)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
[self initLoginForm];
}
return self;
}
-(void)initLoginForm
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 170, 100, 30);
[button setTitle:@"Login..." forState:UIControlStateNormal];
[button addTarget:self action:@selector(handleLoginAttempt) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
how about putting the button in the
viewDidLoadmethod, then add it in theinitLoginForm.Something like this:
or add it in the
viewDidLoadthen hide it, then in theinitLoginFormshow it.