I know this is extremely silly.
I have a view controller that scans a QR code. 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. In that method, that I have implemented in the AppDelegate
I want to present a 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:
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
. If it's only iVar
you should ommit self.
(or consider making it a property
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.