1

テーブルの編集中に [戻る] ボタンを非表示にする if ステートメントを作成しました。

しかし、編集モードを終了すると、戻るボタンが再び表示されません。

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated 
    {
    NSLog(@"Edit");
    bool e = [tableView isEditing];
    e=!e;
    [tableView setEditing:e animated:YES];
    [super setEditing:e animated:YES];

    if (editing)
    {
    [self.navigationItem setHidesBackButton:YES animated:NO];
        UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(pushViewController:animated:)];
        self.navigationItem.leftBarButtonItem = add;
    }
    else if (editing == false)
    {
    self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
    //[self.navigationItem setHidesBackButton:NO animated:NO];
    }
}

NSLog を else ステートメントに追加しましたが、まったく呼び出されていないようです。

編集:私はそれを解決しました.if(editing == true)をif(e == true)に置き換えただけですが、すべての助けに感謝します.

4

3 に答える 3

0

編集:プロジェクトで次のコードを試したところ、意図したとおりに機能し、backButtonが非表示になって再表示されました。

- (IBAction)testButton:(id)sender {
    hide = !hide;
    [self.navigationItem setHidesBackButton:hide animated:NO];
}

非表示はNOで始まります。testButtonを押すたびに、背面が表示または非表示になります。

backButtonが非表示になっているときに、navigationControllerまたはnavigationItemに変更を加えていますか?

于 2012-11-06T12:05:01.083 に答える
0

編集 == false を設定するか、else if を削除して else に置き換える必要があります。現在、編集のために 2 回テストしています == true

if (editing){
    [self.navigationItem setHidesBackButton:YES animated:NO];
    UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(pushViewController:animated:)];
    self.navigationItem.leftBarButtonItem = add;
}else{
    [self.navigationItem setHidesBackButton:NO animated:NO];
}
于 2012-11-06T11:56:54.833 に答える
0

次のように、左バーボタンをデフォルトの戻るボタンにリセットできます。

self.navigationItem.leftBarButtonItem   =   self.navigationItem.backBarButtonItem;

編集:このようにしてみてください。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{
    NSLog(@"Edit");
    bool e = [tableView isEditing];
    e=!e;
   [tableView setEditing:e animated:YES];
   [super setEditing:e animated:YES];

    if (editing)
    {
        UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(pushViewController:animated:)];
        self.navigationItem.leftBarButtonItem = add;
    } 
    else
    {
        self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
    }
}

これを試して。とにかくこれが役に立てば幸いです。:)

于 2012-11-06T11:59:05.190 に答える