ちょっとした質問とシナリオがあります。
質問:[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];
}
不可能なことをしようとしてコードの行を保存しようとするのは怠惰ですか、それとも実際にこれを行うことができますか?私はこれをもっとよく説明できてうれしいです。