首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通用/中央popViewControllerAnimated方法

通用/中央popViewControllerAnimated方法
EN

Stack Overflow用户
提问于 2013-03-13 20:00:17
回答 1查看 151关注 0票数 1

我有一个可爱的小问题和场景:

问:我可以让self.navigationController popViewControllerAnimated:True

从一个中心类被控制,例如必须在每个视图中重复。

这就是我到目前为止所看到的视图:

代码语言:javascript
复制
//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]];

核心类:

代码语言:javascript
复制
@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执行以下操作:

代码语言:javascript
复制
-(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执行以下操作:

代码语言:javascript
复制
-(IBAction)backButtonAction{
     [_NavCtrl popViewControllerAnimated:TRUE];
}

我是不是懒得尝试节省代码行,试图做不可能的事情,或者这真的可以做到吗?我很高兴能更好地解释这一点。

EN

回答 1

Stack Overflow用户

发布于 2013-03-14 02:37:38

好的程序员是懒惰的。

也就是说,如果您正确设置了UINavigationController,它将添加自己的后退按钮,并为您完成此操作。除了[self.navigationController pushViewController:someViewController animated:YES];之外,您不需要任何代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15384725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档