Iphone IOS开发,使用UIAbbarController和UIImagePickerController,如何从一个选项卡转到另一个选项卡?

Iphone IOS开发,使用UIAbbarController和UIImagePickerController,如何从一个选项卡转到另一个选项卡?,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,我似乎找不到答案,或者可能无法理解人们在网上写的东西 我有一个带三个浴缸的大浴盆 其中一个选项卡是UIImagePickerController。该选项卡栏项连接到一个视图控制器,我还将该视图控制器设置为图像选择器(摄影机)的代理 我希望有人拍照或按“取消”,将选择第一个选项卡栏项目(不想停留在装有相机的选项卡栏中) 我的问题是,如何从一个TabBar项中的视图控制器“交谈”TabBar控制器 我的代码位于TakePhotoViewController.m文件中,该文件位于第三个选项卡项中,我想

我似乎找不到答案,或者可能无法理解人们在网上写的东西

我有一个带三个浴缸的大浴盆

其中一个选项卡是UIImagePickerController。该选项卡栏项连接到一个视图控制器,我还将该视图控制器设置为图像选择器(摄影机)的代理

我希望有人拍照或按“取消”,将选择第一个选项卡栏项目(不想停留在装有相机的选项卡栏中)

我的问题是,如何从一个TabBar项中的视图控制器“交谈”TabBar控制器

我的代码位于TakePhotoViewController.m文件中,该文件位于第三个选项卡项中,我想转到第一个项

-(void) viewWillAppear:(BOOL)animated{
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.allowsEditing = NO;
    self.imgPicker.delegate = self;
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController:imgPicker animated:YES];  
}
以及委托方法:

#pragma mark -
#pragma mark - UIImagePicker delegate methods

//saving the image that was taken
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    // Save image
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    [picker release];
}

//alerting the user if the images was saved or not
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;

    // Unable to save the image  
    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                       message:@"Unable to save image to Photo Album." 
                                      delegate:self cancelButtonTitle:@"Ok" 
                             otherButtonTitles:nil];
    else // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                       message:@"Image saved to Photo Album." 
                                      delegate:self cancelButtonTitle:@"Ok" 
                             otherButtonTitles:nil];
    [alert show];
    [alert release];
}

//if user is cancelling the camera
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    [picker release];
}
多谢各位, 埃雷斯

您可以传递所需的选项卡索引值,而不是1


您可以传递所需的制表符索引值,而不是1。

谢谢您,所以我还是很愚蠢。。。。但我不明白self.tabBarController是怎么工作的???这不是我的财产。是因为我在一个超宽带控制器里还是什么?谢谢:-)这就像在根视图以外的后续视图中访问navigationController一样,即使您尚未在那里声明navigationController的属性。你可以从一个viewController中访问tabBarController,它实际上就在tabBarController中。谢谢你,所以我还是很愚蠢。。。。但我不明白self.tabBarController是怎么工作的???这不是我的财产。是因为我在一个超宽带控制器里还是什么?谢谢:-)这就像在根视图以外的后续视图中访问navigationController一样,即使您尚未在那里声明navigationController的属性。您可以从实际位于tabBarController内部的viewController访问tabBarController。
[self.tabBarController setSelectedIndex:1];