开发者

Losing navigation controller how to open another view

I'm currently displaying a UIViewController like this:

AlaramDetail *alaramDetail = [[AlaramDetail alloc] init];
alaramDetail.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:alaramDetail animated:YES];
[alaramDetail release];

all works good but i lose the navigation controller when AlarmDetail o开发者_开发技巧pens. i want to open another view from alarmDetail how can i do so. and how can i return back to my previous navigation controller if i want ? Thx


You need to declare an new navigation controller, add your view controller in it then present modal the navigation controller.

AlaramDetail *alaramDetail = [[AlaramDetail alloc] init];

UINavigationController *newNavigation = [[UINavigationController alloc] initWithRootViewController:alaramDetail];
[alaramDetail release];
newNavigation.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:newNavigation animated:YES];
[newNavigation release];

Edit:

To dismiss modal view:

  1. Easy way: In your modal view in some method that you call to dismiss just add:

    [self.navigationController dismissModalViewControllerAnimated:YES];

  2. More complex way: Implement and delegate protocol on your modal view and make the view controller that presents the modal view the delegate of it. And in the delegate method dismiss the modal view. I do this way when I need to send data from modal view to the controller that present it.


If you are using navigation controller, it should be this way:

AlaramDetail *alaramDetail = [[AlaramDetail alloc] init];
[self.navigationController pushViewController:alaramDetail animated:YES];
[alaramDetail release];


Try this,

`[self.navigationController presentModalViewController:alaramDetail animated:YES]`;

instead of

 [self presentModalViewController:alaramDetail animated:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜