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

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

问题描述

我将一个工作的viewcontroller类从另一个项目复制到一个新项目中。我无法在新项目中加载视图。在旧项目中,我使用了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 ,因为此时它没有像屏幕尺寸这样的信息。

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.

为了获得更高的可靠性,请执行 viewDidAppear: for ViewController 。仍然使用您的计时器系统添加额外的延迟;几分之一秒就足够了。虽然在iOS 5.1模拟器中为我提供了模拟视图控制器,但是<$ href =https://stackoverflow.com/q/6405507/1318452 >在加载另一个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天全站免登陆