[英]Present UIViewController
I know this is extremely silly. 我知道这很愚蠢。
I have a view controller that scans a QR code. 我有一个扫描QR码的视图控制器。 I create it in the
AppDelegate
( didFinishLaunchingWithOptions
), and I also set my AppDelegate
as a delegate for the the view controller which will call a method when he finishes scanning the code. 我在
AppDelegate
( didFinishLaunchingWithOptions
)中创建它,并且还将AppDelegate
设置为视图控制器的委托,该控制器将在完成扫描代码后调用方法。 In that method, that I have implemented in the AppDelegate
I want to present a UINavigationController
. 在那种方法中,我已经在
AppDelegate
实现了,我想呈现一个UINavigationController
。 The problem is that it is not presenting my navigation controller. 问题是它没有显示我的导航控制器。 This is my code:
这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
reader=[ZBarReaderViewController new];
reader.readerDelegate=self;
reader.supportedOrientationsMask=ZBarOrientationMaskAll;
ZBarImageScanner *scanner=reader.scanner;
[scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
[self.window addSubview:reader.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
RootViewController *rootViewController=[[RootViewController alloc] init ]; //create root view controller
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:rootViewController]; // create and init navigation controller with viewController
[navigationController setValue:[[GradientBar alloc] init] forKey:@"navigationBar"];
rootViewController.title=@"mTLU";
[reader presentModalViewController:navigationController animated:NO];
}
Seems like you forgot to set self.window.rootViewController
in didFinishLaunchingWithOptions:
好像您忘记在
didFinishLaunchingWithOptions:
设置self.window.rootViewController
一样didFinishLaunchingWithOptions:
Try: 尝试:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.reader=[ZBarReaderViewController new];
self.reader.readerDelegate=self;
self.reader.supportedOrientationsMask=ZBarOrientationMaskAll;
ZBarImageScanner *scanner=reader.scanner;
[scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
self.window.rootViewController = self.reader;
[self.window addSubview:reader.view];
[self.window makeKeyAndVisible];
return YES;
}
This code assumes reader
is property
of AppDelegate
. 此代码假定
reader
是AppDelegate
property
。 If it's only iVar
you should ommit self.
如果只是
iVar
,则应该忽略self.
(or consider making it a property
). (或考虑将其
property
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.