2009-06-19 7 views
1

私のメインコントローラはUIToolViewControllerのサブクラスで、下部にUIToolBarがあり、行が選択されたときにツールバーなしで別のビューを表示したいと思います。子ビューでUIToolBarを非表示にするにはどうすればよいですか?今はモーダルとして作成されていない限り、すべての子ビューに表示されます。UITableViewControllerの子ビューのUIToolBarを非表示にする

ツールバーはRootControllerに作成されます。

RootController *rootcontroller = [[RootController alloc] initWithStyle:UITableViewStyleGrouped]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootcontroller]; 

[rootcontroller release]; 

[window addSubview:[self.navigationController view]]; 

UIViewController *controller = [[UIViewController alloc] init...] 
[self.navigationController pushViewController:controller animated:YES]; 

RootControllerがアプリデリゲートのapplicationDidFinishLaunchingでそのようにインスタンス化されています

self.toolbar = [[UIToolbar alloc] init]; 
// add tool bar items here 
[self.navigationController.view addSubview:toolbar]; 

RootControllerは、次のようなその子ビューを表示しますRootControll内の[self.view]にツールバーを追加すると代わりにnavigationControllerのビューを使用すると、ツールバーはすべて消えます。

答えて

0

[ツールバーremoveFromSuperview]。

次に、ツールバーを再表示するビューでviewDidAppearメソッドを使用します。 ビューが表示された後にツールバーが追加されるので、viewWillAppearよりもうまく機能します。 (それはちょっと厄介ですのでviewWillAppearのために、ツールバーが遷移中に追加されます。)

2

子ビューを 'toolbar.hidden = YES'で表示してからviewWillAppearメソッドで表示する前に、ツールバーを隠すことができます。隠し=いいえ '。別の代替は、 "removeFromSuperview" を使用することになる

0

私はそれがこの

- (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]; 



[[self tableView] reloadData]; 

} 

- (void) info_clicked:(id)sender { 


[self.navigationController popViewControllerAnimated:YES]; 
[toolbar removeFromSuperview]; 

} 
を確認し、この

[toolbar removeFromSuperview]; 

と協力しました

関連する問題