通用/中央popViewControllerAnimated方法



我有一个甜蜜的小问题和场景:

问题:我可以拥有[自我]吗?实现通过调用popViewControllerAnimated导航控制器:真]

从一个中心类控制,而不是在每个视图中重复。

所以这是我目前所拥有的:观点:

//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];
}

我是不是懒于试图保存代码行,试图做不可能的事,或者这实际上是可以做到的?我很乐意解释得更好。

优秀的程序员是懒惰的。

也就是说,如果你正确设置了UINavigationController它会添加它自己的后退按钮并为你做这些。除了[self.navigationController pushViewController:someViewController animated:YES];

你不需要任何代码

相关内容

  • 没有找到相关文章

最新更新