I have made a UIView which contains a table and some buttons. This view is called by a UIViewController which is called by a tab-bar controller. There is no IB involved.
When the view comes up it only has the outlines of the objects. e.g. the following button comes out without its label:
brect = CGRectMake(80, 330, 60, 27);
centern=CGPointMake(CGRectGetMidX(brect), CGRectGetMidY(brect) );
UIButton * button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button2 setFrame:brect];
[button2 setCenter:centern];
[button2 setTitle:@"Delete" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(deldate:) forControlEvents:UIControlEventTouchUpI开发者_开发百科nside];
[self addSubview:button2];
As soon as I make the first touch everything appears as it should.
What am I doing wrong?
[self.view addSubview:button2];
self is an instance of UIViewController. self contain a view. you should add you UIButton to view, not viewController.
精彩评论