Reputation: 147
So I have a view and in my viewcontoller class I try and add a subview with the following code .
UIButton *test = [[UIButton alloc]initWithFrame:CGRectMake(30, 100, 100, 100)];
[self.view addSubView:test];
Nothing happens, no errors or anything. I know its being called because it is in the viewdidload method. I have a separate class were i subclass uiview could that have anything to do with it?
Upvotes: 0
Views: 161
Reputation: 14427
You need to make sure you add all the needed attributes of that button:
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[test addTarget:self action:@selector(selector:) forControlEvents:UIControlEventTouchDown];
[test setTitle:@"Button Title" forState:UIControlStateNormal];
test.frame = CGRectMake(30, 100, 100, 100);
[view addSubview:test];
Upvotes: 0
Reputation: 66302
UIButton *test = [UIButton buttonWithType:UIButtonTypeRoundedRect];
test.frame = CGRectMake(30, 100, 100, 100);
[self.view addSubView:test];
Upvotes: 1