Objective C: Using code to add a toolbar to a UITableView (within a Navigation Controller)

℡╲_俬逩灬. 提交于 2019-12-07 07:47:41

问题


I managed to add a toolbar at the bottom of my UITableView using the code below:

toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
toolbar.frame = CGRectMake(0, 436, 320, 50);


//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];

[self.navigationController.view addSubview:toolbar];

However when I try to switch back to the first page of the navigation controller, the toolbar at the bottom of the page is still displayed. How can I ensure that the toolbar is only shown on the UITable View and not any other views in the navigation controller?

Thanks in advance.

Zhen


回答1:


In your TableViewController implement:

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.toolbar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.toolbar.hidden = YES;
}


来源:https://stackoverflow.com/questions/5754692/objective-c-using-code-to-add-a-toolbar-to-a-uitableview-within-a-navigation-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!