开发者

presentModalViewController on parent viewcontroller

开发者 https://www.devze.com 2023-02-10 01:47 出处:网络
I have a viewcontroller, where I load subviews on. In those subviews I have a UIButton which will show a modalViewController. If I call the function on the main viewcontroller, I get the modal exactly

I have a viewcontroller, where I load subviews on. In those subviews I have a UIButton which will show a modalViewController. If I call the function on the main viewcontroller, I get the modal exactly in the middle as I want them to be, but if I call the exact same method in the view I've added as a subview the modal is presented somewhere on the right side of the screen. So now is my question: how can I present the modal on the super view instead? Or how do I put the modalview in center? Because the views I've added as subviews contains data which the modalpopup needs.

This is how I present the modal:

MapViewer *map = [[MapViewer alloc] init];
map.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:map animated:YES];
[map release];

Hope somebody can help me with this.

Thanks in advance!

Edit:

Maybe useful to be more clear:

AppDelegate.m

-> MainWindow.m

-> OtherViewController.m

So I add an x amount of OtherViewControllers as subviews to MainWindow. The OtherViewController contains the function mentioned above. But the map needs to be displayed as a modal on the MainWindow, and not on the OtherViewController so it gets nicely ce开发者_如何学运维ntered etc.


One thing you might do is set the target of the UIButton object to the main view controller using setTarget:action: method.


Ok I've managed to get it working using the notificationcenter so I can call a method on the MainWindow from other views. So if anyone is asking the same question, have a look at the notificationcenter :D

0

精彩评论

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