我正在尝试从另一个视图控制器加载临时滑入视图。我的应用程序的视图控制器是结构化的:

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运行应用程序时,我可以导航到视图,单击我的按钮,并出现一个空白的白色屏幕(请注意,这不是应该加载的视图的白色背景)。

有帮助吗?

解决方案

你应该这样做..

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

其他提示

我认为视图控制器的modalTransitionStyle适用于来自视图控制器的模态视图。因此,如果要使用UIModalTransitionStyleCoverVertical转换来显示模态控制器,则应在父视图控制器(self)上设置modalTransitionStyle属性,而不是新视图。

我没有使用modalTransitionStyle的经验,但是在加载视图之前设置该属性会导致一些问题?我试着把它评论出来......

听起来IB中的所有内容都配置正确。只要您的文件所有者是视图控制器,并且它的视图出口绑定到视图就应该是好的。

希望有所帮助,

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top