无法让presentViewController 工作 [英] Unable to get presentViewController to work

查看:24
本文介绍了无法让presentViewController 工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从另一个项目复制了一个工作视图控制器类到一个新项目中.我无法在新项目中加载视图.在旧项目中我使用了presentModalViewController.在新的我无法使用presentModalViewController 或presentViewController 加载视图

I copied a working viewcontroller class from another project into a new project. I can't get the view to load in the new project. In the old project I used presentModalViewController. In the new I cannot get the view to load using either presentModalViewController or presentViewController

我正在尝试从我的主视图控制器加载当前视图.

I am trying to load the present the view from my main view controller.

这是我的主视图控制器界面的样子...

Here is what my main view controller interface looks like...

//  ViewController.h
#import <UIKit/UIKit.h>
#import "RequestDialogViewController.h"

@interface ViewController : UIViewController <RequestDialogViewControllerDelegate> {

}

- (void)requestDialogViewDidDismiss:(RequestDialogViewController *)controller withResponse:(NSString*)response;

我正在像这样使用presentModalViewController...

I am using presentModalViewController like this...

RequestDialogViewController *requestIPViewController = [[RequestDialogViewController alloc] initWithNibName:@"RequestDialogViewController"  bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:requestIPViewController];
[self presentModalViewController:navigationController animated:YES];

和presentViewController这样...

and presentViewController like this...

RequestDialogViewController *requestIPViewController = [[RequestDialogViewController alloc] initWithNibName:@"RequestDialogViewController"  bundle:nil];    
[self presentViewController:requestIPViewController animated:YES completion:nil];

我在新项目中缺少什么?init 方法会触发,但 viewDidLoad 不会触发,也不会显示任何内容.

What am I missing in the new project? The init method fires, but viewDidLoad does not and nothing is displayed.

谢谢

推荐答案

如果 ViewController 是根视图控制器,它不能从它自己的 viewDidLoad<中呈现一个模态视图控制器/code>,因为那时它没有屏幕大小等信息.

If ViewController is the root view controller, it can't present a modal view controller from within its own viewDidLoad, because at that point it doesn't have information like the screen size.

如果其他视图控制器已经显示,这将起作用.如果根视图控制器是 UINavigationController,您将看到一个视图从右侧滑入,而模态视图从底部向上滑动.

If other view controllers have already displayed, this will work. If the root view controller is a UINavigationController, you will see a view sliding in from the right while the modal view slides up from the bottom.

无论如何,对于您的 ViewController,您最快可以在它变得可见后呈现它.为此使用计时器是不可靠的;较旧和较慢的设备具有更长的加载时间.

Anyway, for your ViewController, the soonest you could present it is after it has become visible. Using a timer for this is unreliable; older and slower devices have dramatically longer load times.

为了获得更高的可靠性,为 ViewController 实现 viewDidAppear:.仍然使用你的计时器系统来增加额外的延迟;几分之一秒就足够了.尽管在 iOS 5.1 模拟器中从 viewDidAppear 中呈现模态视图控制器对我有用,呈现模态视图控制器加载另一个 ViewController 时 说它有时不会发生.

For more reliability, implement viewDidAppear: for ViewController. Do still use your timer system to add an additional delay; a fraction of a second should be sufficient. Although presenting the modal view controller from within viewDidAppear worked for me in the iOS 5.1 simulator, Presenting a modal view controller when loading another ViewController says it sometimes doesn't happen.

这篇关于无法让presentViewController 工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆