1

すべてのクラスに多くのviewcontrollerクラスとtableviewcontrollerクラスがある私のアプリケーションでは、持っているnavigationcontrollerを表示したい

//creation of toolbar
UIToolbar *tool = [UIToolbar new];
tool.frame = CGRectMake(0, 0, 320, 42);
//create setting button
UIButton *bttn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
[bttn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *back=[[UIBarButtonItem alloc]initWithCustomView:bttn];

//Space
UIBarButtonItem *spbtn = [[UIBarButtonItem alloc] init];

spbtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
         UIBarButtonSystemItemFlexibleSpace   target:nil action:nil];

//Show Logo
UIButton *bttn1;
bttn1= [UIButton buttonWithType:UIButtonTypeCustom];
bttn1.frame = CGRectMake(20, 0, 230, 30);
bttn1.backgroundColor = [UIColor clearColor];
[bttn1 addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
UIImage *imgss =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"pic" ofType:@"png"]];
UIImage *strechableImage1 = [imgss stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[bttn1 setBackgroundImage:strechableImage1 forState:UIControlStateNormal];
UIBarButtonItem *logo;
logo=[[UIBarButtonItem alloc]initWithCustomView:bttn1];

//assign toolbar into navigation bar
NSArray *items = [NSArray arrayWithObjects:back,logo,spbtn,nil];
[tool setItems:items animated:YES];
tool.barStyle =UIBarStyleBlackOpaque;
tool.backgroundColor = [UIColor clearColor];
self.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc] initWithCustomView:tool];

すべてのクラスの上部に移動ツールバーを表示したい。このため、すべてのクラスでこのコードを記述する必要がありますが、繰り返しを削除したい静的メソッドを持つクラスを定義しますこのメソッドでそのアクションを実行しようとしますが、エラーが生成されます。

4

3 に答える 3

0

UINavigationController には既にツールバーがあります。それを有効にする場合は、viewControllers からツールバーに配置する必要があるボタンを提供するだけです。Apple のメール アプリケーションは、この概念を使用しています。これの利点は、ナビゲーション スタック アニメーション中にツールバーが画面から離れないことです。これにより、現在画面上にある UIViewController に従って、ツールバーがすべての上に置かれ、ツールバーのボタンが変化するように見えます。

于 2010-07-29T01:33:40.870 に答える
0

解決策は継承の概念によって非常に単純であることがわかり、ナビゲートされたツールバーを表示する基本クラスを作成し、基本クラスをファイルのスーパークラスとして使用します

于 2010-07-26T12:07:43.683 に答える
0

はい、使用できます

self.navigationbar を使用することは可能ですか。

于 2010-07-24T13:19:29.790 に答える