use*_*002 2 objective-c uiwebview viewdidload viewwillappear ios
我试图将UIToolBar添加到UIWebView中,但每当我在viewDidLoad中插入此代码时UIToolBar都没有显示,但是当在viewWillAppear中完成时,它可以工作.有人可以向我解释一下.
-(void)viewDidLoad
{
[super viewDidLoad];
self.forwardButton = [[UIBarButtonItem alloc]initWithTitle:@"Forward" style:UIBarButtonItemStylePlain target:self action:@selector(forward)];
self.backButton = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
NSArray *buttonsArray = @[self.backButton,self.forwardButton];
CGRect toolBarFrame = CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44);
self.toolbar = [[UIToolbar alloc]initWithFrame:toolBarFrame];
[self.toolbar setItems:buttonsArray animated:YES];
[self.toolbar sizeToFit];
[self.view addSubview:self.toolbar];
}
Run Code Online (Sandbox Code Playgroud)
添加子视图viewDidLoad
,但将其设置frame
为viewWillAppear
.self.view.frame
正在被viewWillAppear
UIKit调用之前正在设置.您获得的值viewDidLoad
是在nib中设置的值,通常与实际值不同frame
.
不要忘记设置autoresizingMask
或使用自动布局.
归档时间: |
|
查看次数: |
853 次 |
最近记录: |