ツールバーコントロールをIBから削除しましたが、代わりにスルーコードを作成しようとしました。私はオンラインで見つけた次のコードを試しました。このコードを "viewWillAppear"に書くのではなく、同じUIViewControllerのナビゲーションバーの "bar button item"に自分のコードがあります。プログラムで完了したときにツールバーが表示されない
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Initialize the toolbar
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];
//Caclulate the height of the toolbar
CGFloat toolbarHeight = [toolbar frame].size.height;
//Get the bounds of the parent view
CGRect rootViewBounds = self.parentViewController.view.bounds;
//Get the height of the parent view.
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
//Get the width of the parent view,
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
//Reposition and resize the receiver
[toolbar setFrame:rectArea];
//Create a button
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];
[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
//Add the toolbar as a subview to the navigation controller.
//[self.navigationController.view addSubview:toolbar];
// Instead of adding to a navigation controller (which I don't have), I'm adding directly to the view and is not shown at all.
// Hiding the tabBar before I show the toolbar
[self.tabBarController.tabBar setHidden:YES];
[self.view addSubview: self.toolbar];
私はここで間違っていますか? info_clickedメソッドを使用できるようにする必要がありますか(bar button item click)?
お知らせください。
これはIOSの表示について私の知らないことですが、どのビューサブクラスのデフォルトイニシャライザでもない-initWithFrame: '? – Daniel