我有一个甜蜜的小问题和场景:
问题:我可以拥有 [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];
}
我是否懒于尝试保存尝试做不可能的代码行,或者这实际上可以做到吗?我很乐意更好地解释这一点。