使用'presentModalViewController'加载视图 [英] 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];
}
我已经验证了我的WOTimePickerViewController是成功地从init方法返回的,但是视图从未输入它的viewDidLoad方法.
I have verified that my WOTimePickerViewController is successfully returning from the init method but the view never enters it's viewDidLoad method.
因此,如果我查看IB中的视图,它似乎已连接到vc的"view"属性.当我在模拟器中(从IB)运行视图时,它将正确呈现.
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.
当我从XCODE运行该应用程序时,可以导航到该视图,单击我的按钮,然后出现空白的白色屏幕(请注意,这不是应该加载的视图的白色背景).
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).
推荐答案
您应该这样做..
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.
您应该这样做:
[self.navigationController presentModalViewController:tpvc animated:YES];
,当您要关闭modalView控制器时,您应该这样做:
and when you want to dismiss the modalView controller you should do it like:
[self.navigationController dismissModalViewControllerAnimated:YES];
这篇关于使用'presentModalViewController'加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!