我有一个可爱的小问题和场景:
问:我可以让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).
@endsetGenericBackButton执行以下操作:
-(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];
}我是不是懒得尝试节省代码行,试图做不可能的事情,或者这真的可以做到吗?我很高兴能更好地解释这一点。
发布于 2013-03-14 02:37:38
好的程序员是懒惰的。
也就是说,如果您正确设置了UINavigationController,它将添加自己的后退按钮,并为您完成此操作。除了[self.navigationController pushViewController:someViewController animated:YES];之外,您不需要任何代码
https://stackoverflow.com/questions/15384725
复制相似问题