我知道这非常愚蠢。
我有一个扫描QR码的视图控制器。我在AppDelegate
(didFinishLaunchingWithOptions
)中创建它,并且我还将AppDelegate
设置为视图控制器的委托,该控制器将在完成扫描代码时调用方法。在那个方法中,我已经在AppDelegate
中实现了我想要呈现UINavigationController
。问题是它没有呈现我的导航控制器。这是我的代码:
- (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];
}
答案 0 :(得分:0)
好像忘了在self.window.rootViewController
didFinishLaunchingWithOptions:
尝试:
- (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;
}
此代码假定reader
为property
的{{1}}。如果只是 AppDelegate
,您应该省略iVar
(或考虑将其设为self.
)。