Reputation: 4984
I created a new iPad app using XCode4 and Storyboard. I have several (5) various view controllers. I created a class (HomeViewClass), and took one of the view controllers and and changed the class to "HomeViewClass", and put this code in the viewDidLoad method. I originally had this in a non-storyboard project, where it worked perfectly... (it's looping where indicated).
allButtons = [NSMutableArray array];
for(int k = 40, m = 0; m < 6; m++, k+= 42) // this controls the vertical distance between rows
for(int i = 0, j=182; i < 7; i++, j+=82) { // this controls the size (j) and horizontal distance
calendarButton *cb= [calendarButton buttonWithType:UIButtonTypeCustom];
[cb makeFrame:CGRectMake(j, k, 80, 40) number: allButtons.count+1 color:[UIColor orangeColor]];
// x y w h
[self.view addSubview:cb]; // <------------------- causing a viewDidLoad loop
[allButtons addObject:cb]; // put it in the array
}
How do I fix this?
Upvotes: 0
Views: 313
Reputation: 3852
You should cache self.view in a local variable and check that you called [super viewDidLoad] at the beginning of your method:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *rootView = self.view;
for(int k = 40, m = 0; m < 6; m++, k+= 42) {
for(int i = 0, j=182; i < 7; i++, j+=82) {
UIButton *cb = [UIButton buttonWithType:UIButtonTypeCustom];
[rootView addSubview:cb];
}
}
}
Upvotes: 4