Reputation: 96411
On one of the scenes in my storyboard, i placed a button. It shows on the view fine.
The view itself is represented by class GameView
, which contains both
IBOutlet UIButton *b;
@property (strong) IBOutlet UIButton *b;
I have connected the outlet to button from the storyboard's view.
From .m
file of the GameView
class, i:
[[self b] setFrame:CGRectMake(420, 260, 50, 30)];
[b setTitle:@"!!!" forState:UIControlStateNormal];
[self addSubview:[self b]];
When button is created programmatically, the following works fine
deal = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[deal setFrame:CGRectMake(420,170, 50, 30)];
[deal setTitle:@"Deal" forState:UIControlStateNormal];
[self addSubview:[self deal]];
When program runs, however, the button from the storyboard is not seen. Why?
Upvotes: 1
Views: 539
Reputation: 96411
I am an epic newb. Posting the answer in hopes someone else might find it useful.
Basically, in my case, the view is created programmatically from the controller, whatever is seen on the screen of a storyboard is effectively replaced on object creation.
UIView *gameView = [[GameView alloc] initWithFrame:CGRectMake(0, 0, 480, 300)];
[[self view] addSubview:gameView];
Once i put IBOutlets
into the Controller
and added
[bb setFrame:CGRectMake(420, 260, 50, 30)];
[bb setTitle:@"---" forState:UIControlStateNormal];
[gameView addSubview:[self bb]];
It worked like a charm.
Upvotes: 1