English 中文(简体)
cocoa iphone load modal view without seeing it
原标题:

Is there a way to load a view modally without seeing it? I need to access methods on the modal view controller which in turn set properties of UI components in a XIB. I want to set those properties, but I don t want to see the view right away. I want to reveal it when the user rotates the phone.

Everything is working, except the solution involves presenting the modal view as soon as the app loads.

Thanks, Howie

最佳回答

In a view controller you can create an outlet for another controller. All you need to do is something like this in the same nib file in interface builder:

MainController         UIViewController
->UIview               UIView

ModalController        UIViewController
->ModalControllerView  UIView

in MainController.h, create an outlet for the view controller:

@property(nonatomic, retain) IBOutlet ModalController *ModalController

(and of course you need the ivar and include also)

In Interface Builder, connect ModalController mainController to the ModalController view using option drag or however you want.

When the nib loads, you ll get modalController set to an instantiated ModalController, then methods in MainController can access modalController and do whatever they want to it. Then you just have to use presentModalView to present it.

I think the more typical way to do this, though, is this:

- (IBAction)showInfo {    

    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}

(That s directly from the Utility Application project template in Xcode.)

In other words, create the modal controller and view in it s own nib file then load the nib file manually as needed. This is more memory efficient since it doesn t instantiate the object until it s actually needed.

There s also no reason why you can t just do:

    modalController = [[ModalViewController alloc] initWithNibName:@"ModalView" bundle:nil];

in MainController s viewDidLoad or initWithCoder method or something, then proceed to configure it however you want.

问题回答

If you have another view, could you insert this view under the existing view using

(void)insertSubview:(UIView *)view atIndex:(NSInteger)index

then when the device rotates, switch the views?





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签