博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
push与presentModal的 用法详解(转)
阅读量:7286 次
发布时间:2019-06-30

本文共 2708 字,大约阅读时间需要 9 分钟。

这两个方法都是必须要ViewController, 是建立在UINavigationController之上的。

SQLiteViewController *baSQLiteViewController = [[SQLiteViewController alloc] init];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:baSQLiteViewController];
[self.window addSubview:nav.view];

推出视图push,下一页面会自动添加返回按钮

InforViewController *baInforViewController = [[InforViewController alloc] init];
[self.navigationController pushViewController:baInforViewController animated:YES];

 

以Modal方式推出一个视图,弹出的视图没有返回按钮,需要自己添加

NewDataViewController *baNewViewController = [[NewDataViewController alloc] init];
UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:baNewViewController];
[self.navigationController presentModalViewController:baNavigation animated:YES];
[baNewViewController release];
[baNavigation release];

为弹出视图添加返回按钮

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(returnView)];

返回方法

- (void)returnView

{

    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

总结:

1 将需要present(需要弹出来的)的ViewController先添加加到一个新的UINavigationController的RootView中,例如

NewDataViewController *baNewViewController = [[NewDataViewController alloc] init]; //需要弹出的ViewController

UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:baNewViewController];//实例化一个NavigationController对象,这个对象使用将要弹出ViewController作为RootView Controlller初始化。

2. 然后present这个UINavigationController,接着就可以继续push了,当返回到present还可以缩回去

右侧进入

BaseInfoEdit *View = [[BaseInfoEdit alloc] initWithNibName:@"BaseInfo" bundle:nil];

[self.navigationController pushViewController:View animated:YES];

返回方法

[self.navigationController popViewControllerAnimated:YES];

下方进入

OilRecordAdd *View = [[OilRecordAdd alloc] initWithNibName:@"OilRecordDetail" bundle:nil];

[self.navigationController presentModalViewController:Nav animated:YES];

返回方法

[self.navigationController dismissModalViewControllerAnimated:YES];

leftBarButtonItem和rightBarButtonItem设置的是本级页面上的BarButtonItem,
backBarButtonItem设置的是下一级页面上的BarButtonItem
比如:两个ViewController,主A和子B,我们想在A上显示“刷新”的右BarButton,B上的BackButton显示为“撤退”
就应该在A的viewDidLoad类似方法中写:

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:nil];

self.navigationItem.rightBarButtonItem = refreshButton;

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"撤退" style:UIBarButtonItemStylePlain target:self action:nil];

self.navigationItem.backBarButtonItem = cancelButton;

B不需要做任何处理

然后A push B就可以了

 

转载于:https://www.cnblogs.com/junxiaohu/archive/2013/04/07/3003515.html

你可能感兴趣的文章
基于底层事件的录制回放实现
查看>>
ethos从入门到精通-4.1映泰主板bios设置
查看>>
js 去除字符串空白符
查看>>
我的友情链接
查看>>
UC浏览器QQ浏览器欧朋浏览器使用体会
查看>>
Tcmalloc优化Nginx内存管理
查看>>
Spring那些不得不知的细节
查看>>
java获取本机ip,mac,os名称,版本等
查看>>
P2077 红绿灯
查看>>
我的友情链接
查看>>
jsp中的回车事件
查看>>
Linux php 扩展安装 mongo ,redis ,soap,imap,pdo_mysql,o
查看>>
Tee(Linux命令)
查看>>
android.widget.Spinner
查看>>
LAMP下tomcat使用命令
查看>>
ipvsadm 命令积累
查看>>
go的time
查看>>
SQL语句大全
查看>>
路由器怎么设置映射?
查看>>
LayoutAnimation的使用
查看>>