1

ちょっとした質問とシナリオがあります。

質問:[self.navigationController popViewControllerAnimated:True]を入手できますか

すべてのビューで繰り返される必要があることを意図した中央クラスから制御されています。

だからこれは私がこれまでに持っているものです:ビュー:

//this is all I want to accomplish and repeat in every view. I want to pass on the own NavigationController and have central class add an action (and style) to the leftBarButton

[self.navigationItem setLeftBarButtonItem:[actionsCollection setGenericBackButton:self.navigationController]];

中央クラス:

@interface ActionsCollection ()
@property(nonatomic, weak)UINavigationController *NavCtrl; // I do this since I dont seem to be able to pass the self.NavigationController on to the buttons action selector (se bellow).
@end

setGenericBackButtonは次のことを行います。

-(UIBarButtonItem *)setGenericBackButton:(UINavigationController *)NavContrl{
     _NavCtrl = NavContrl; // so that I can get a the global (to the class) UINavigationController being reached from -(IBAction)backButtonAction (see bellow)

     UIButton* myBackButton = [ButtonMaker BtnTypeBack]; //just returns a styled btn

//this is where it starts to fail - I want to pass the 'NavContrl' on with the selector bunt havnt figured out how (thats why the global variable '_NavContrl'
    [myBackButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem* BackBtnItem = [[UIBarButtonItem alloc]initWithCustomView:myBackButton];

}

backButtonActionは行います:

-(IBAction)backButtonAction{
     [_NavCtrl popViewControllerAnimated:TRUE];
}

不可能なことをしようとしてコードの行を保存しようとするのは怠惰ですか、それとも実際にこれを行うことができますか?私はこれをもっとよく説明できてうれしいです。

4

1 に答える 1

0

優れたプログラマーは怠け者です。

つまり、 UINavigationController を適切に設定すると、独自の戻るボタンが追加され、これが行われます。それ以上のコードは必要ありません[self.navigationController pushViewController:someViewController animated:YES];

于 2013-03-13T18:37:38.423 に答える