目前的UIViewController

时间:2012-03-28 10:07:17

标签: iphone ios xcode uiviewcontroller

我知道这非常愚蠢。

我有一个扫描QR码的视图控制器。我在AppDelegatedidFinishLaunchingWithOptions)中创建它,并且我还将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];

}

1 个答案:

答案 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;
}

此代码假定readerproperty的{​​{1}}。如果只是 AppDelegate,您应该省略iVar(或考虑将其设为self.)。