分享

pushViewController presentModalViewController 用法

 没原创_去搜索 2015-07-17
两个方法都是用ViewController是建立在UINavigationController之上的
例如:
TestViewController *testViewController = [[TestViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: testViewController];
[self.window addSubview:nav.view];

UINavigationController是导航控制器,如果pushViewController的话,会跳转到下一个ViewController,点返回按钮会回到现在这个ViewController,推出试图push,下一页面会自动添加返回按钮
例如:
UserPushViewController *pViewController = [[UserPushViewController alloc] init];

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


用UINavigationController的时候用pushViewController:animated,其他时候用presentModalViewController:animated

上推一个试图,下一页没有返回按钮,需要自己添加

NewDataViewController *baNewViewController = [[NewDataViewController alloc] init];

UINavigationController *baNavigation = [[UINavigationController allocinitWithRootViewController: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];

}


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多