开发者

Using 'presentModalViewController' to load a view

I am attempting to load a temporary, slide-in, view from another view controller. My application's view controllers are structured:

Application > Tab Bar Controller > TabBarItem > View Controller

In this view controller, I have a button that successfully fires a method to load the temporary view:

- (IBAction)displayTimePickerViewForDayButton:(id)sender {

    NSLog(@"displayTimePickerViewForDayButton method entered.");

    // create the selector view controller and开发者_运维问答 become the delegate
    WOTimePickerViewController *tpvc = [[WOTimePickerViewController alloc] initWithNibName:@"WOTimePickerView" bundle:nil];
    tpvc.delegate = self;
    tpvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

    [self presentModalViewController:tpvc animated:YES];
    [tpvc release];
}

I have verified that my WOTimePickerViewController is successfully returning from the init method but the view never enters it's viewDidLoad method.

So, if I look at the view in IB, it appears to be connected to the vc's "view" property. When I run the view in the simulator (from IB) it renders correctly.

When I run the app from XCODE, I can navigate to the view, click my button, and a blank white screen appears (note this is not the white background of the view that should load).


You should do it like this..

WOTimePickerViewController *tpvc = [[WOTimePickerViewController alloc] initWithNibName:@"WOTimePickerView" bundle:nil];
    tpvc.delegate = self;
UINavigationController *navCntrlr = [[UINavigationController alloc] initWithRootViewController:tpvc];
    navCntrlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

    [self.navigationController presentModalViewController:tpvc animated:YES];
    [tpvc release];

But the important thing you are missing is you are not doing it right.

you should do it like:

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

and when you want to dismiss the modalView controller you should do it like:

[self.navigationController dismissModalViewControllerAnimated:YES];


I think the modalTransitionStyle of the view controller applies to modal views shown from that view controller. So if you want to use the UIModalTransitionStyleCoverVertical transition to display your modal controller, you should set the modalTransitionStyle property on the parent view controller (self), not the new one.

I don't have any experience using the modalTransitionStyle, but maybe setting that property before the view is loaded is causing some issues? I'd try commenting it out...

It sounds like everything is configured correctly in IB. As long as your File's Owner is the view controller, and it's view outlet is bound to the view you should be good.

Hope that helps,

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜