2009-11-28 72 views
2

我试图从另一个视图控制器加载一个临时的幻灯片视图。我的应用程序的视图控制器结构:使用'presentModalViewController'加载视图

Application > Tab Bar Controller > TabBarItem > View Controller 

在这个视图控制器,我有一个按钮,成功触发一个方法来加载临时视图:

- (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方法。

所以,如果我看看IB的视图,它似乎连接到vc的“视图”属性。当我在模拟器(从IB)中运行视图时,它可以正确渲染。

当我从XCODE运行应用程序时,我可以导航到视图,单击我的按钮,并出现一个空白的白色屏幕(注意,这不是应加载的视图的白色背景)。

+0

建设的问题?也许你可以尝试删除项目目录中的'build'目录,然后再使用Xcode进行编译。所有的资源应该在那时正确地更新。 – Joost 2009-11-29 10:08:26

回答

4

你应该做这样的..

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]; 

但你缺少最重要的是你是不是做是正确的。

你应该这样做,如:

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

,当你想关闭该modalView控制器,你应该这样做,如:

[self.navigationController dismissModalViewControllerAnimated:YES]; 
+1

只要他从UIViewController派生类中调用presentModalViewController,我不明白他为什么需要使用导航控制器。你需要一个导航控制器来使用pushViewController。 – Oscar 2011-01-17 10:15:43

1

我认为视图控制器的modalTransitionStyle适用于显示模式视图该视图控制器。所以如果你想使用UIModalTransitionStyleCoverVertical过渡来显示你的模态控制器,你应该在父视图控制器(self)上设置modalTransitionStyle属性,而不是新的。

我没有任何使用modalTransitionStyle的经验,但也许在视图加载之前设置该属性导致一些问题?我会尝试评论它...

这听起来像是在IB中正确配置了一切。只要你的文件的所有者是视图控制器,并且它的视图出口绑定到视图,你应该是好的。

希望帮助,

相关问题