3

ツールバーが非表示と再表示に設定された後、ボタンが消える理由がわかりません。どうすれば修正できますか?

ボタンコードを設定する

-(void)viewDidAppear:(BOOL)animated {
    //NSLog(@"viewDidAppear ");

    [self becomeFirstResponder];
    //Create a button
    UIBarButtonItem *back = [[UIBarButtonItem alloc] 
                        initWithBarButtonSystemItem:UIBarButtonSystemItemRewind 
                target:self action:@selector(goback:)];

    UIBarButtonItem *fixspace1 = [[UIBarButtonItem alloc] 
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                                 target:self action:nil];

    UIBarButtonItem *next = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward 
                             target:self action:@selector(gofwd:)];
    UIBarButtonItem *stop = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemStop 
                             target:self action:@selector(stopload:)];

    UIBarButtonItem *refresh = [[UIBarButtonItem alloc] 
                             initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 
                             target:self action:@selector(refreshWeb:)];


    [self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
    [self.navigationItem setRightBarButtonItem:refresh animated:YES];

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

    [stop release];
    [next release];
    [back release];
    [refresh release];
    [fixspace1 release];
}

この方法でボタンを設定します

-(void)viewDidAppear:(BOOL)animated 

このコードはツールバーを非表示にするために使用します

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
    [self.navigationController setToolbarHidden:YES animated:YES];

代替テキスト

4

3 に答える 3

9

ツールバー項目を設定するための文書化されたメソッドは、ViewControllerのtoolbarItemsプロパティを介して行われます。同じUINavigationControllerリファレンスでも、プロパティが読み取り専用としてリストされておりtoolbar、特に警告が表示されます

UIToolbarオブジェクトを直接変更しないでください。

したがって、変更してみてください

[self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];

[self setToolbarItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
于 2010-03-24T01:35:32.267 に答える
1

これ以上の答えがないので、以前のコメントを宣伝します。この行を取り出してみてください:

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

私はそのようなことを実験したことはありませんが、それは間違っているように見え、iPhoneSDKの哲学に非常に反しています。コントローラオブジェクトにすでにツールバーへのポインタがある場合、なぜそれをビューに追加する必要があるのでしょうか。それが適切な場所である場合、コントローラーオブジェクトはそれ自体を実行します。

于 2010-03-20T23:45:23.303 に答える
0

ツールバーに追加した直後にツールバーボタンを離す必要があるのではないかと思います。それらをインスタンス変数に保存し、で解放する必要がありますdealloc

于 2010-03-20T21:35:41.440 に答える