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 回答