从UITabBarController呈现的模态viewController

时间:2012-03-08 02:48:19

标签: iphone objective-c ios cocoa-touch

我有一个类是UITabBarController的子类,它包含4个子视图控制器。我添加了一个类似于RedLaser,Instagram,Path,DailyBooth和其他应用程序的按钮。我的就像这里的榜样:

Image of tabBar with center button

此按钮调用TabBarController中的方法,该方法呈现模态viewController。当它被解除时,当前所选viewController中的NavigationControllers开始表现得很奇怪。在您选择tabBar上的另一个选项卡之前,pop动画都会搞砸,并且会发生其他小错误。然后动画就可以了,直到再次呈现viewController。

我确定这是因为我错误地解雇了它,但我不确定如何做到这一点。

这是我在TabBarController中的代码:

-(void)showScanner {
    ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    [scanner setSymbology:ZBAR_I25
                   config:ZBAR_CFG_ENABLE
                       to:0];
    [scanner setSymbology:ZBAR_QRCODE
                   config:ZBAR_CFG_ENABLE
                       to:0];

    [reader setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:reader
                            animated:YES];
    [reader release];
    //[self playBeep];
    }

-(void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info {
    id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for (symbol in results)
        break;
    NSString *barcode = symbol.data;

    UINavigationController *searchNavController = [[self viewControllers] objectAtIndex:1];
    WLSearchViewController *searchVC = [searchNavController.viewControllers objectAtIndex:0];

    //    WLSearchViewController *searchVC = [[self viewControllers] objectAtIndex:1];
    //[searchNavController popToRootViewControllerAnimated:NO];
    [self setSelectedViewController:searchNavController];
    [self dismissModalViewControllerAnimated:YES];

    [self playBeep];

    [searchVC handleSearchForTerm:barcode];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:4)

发现了什么问题,我想发布这篇文章是为了帮助其他任何正面对此问题的人。

我覆盖了一个viewDidAppear:animated:在我的tabBarController中,但我没有调用[super viewDidAppear:animated:]

补充说,一切都更好!