0
我似乎無法找到答案,或者可能無法理解人們在網絡上寫的東西...iOS開發,使用UITabBarController和UIImagePickerController,如何從一個標籤到另一個?
我有一個帶3個浴盆的UITabBar。
其中一個選項卡是UIImagePickerController。此TabBar項目連接到一個視圖控制器,我也設置爲圖像選擇器(相機)的代表。
我希望有人拍照或按取消,第一個TabBar項目將被選中(不想留在持有相機的TabBar中)。
我的問題是,我該如何與位於TabBar項目之一的視圖控制器中的TabBar控制器「交談」?
我的代碼在第三個TabBer項目中的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];
}
非常感謝你, 埃雷茲
謝謝,所以我再次出來愚蠢....但我不明白如何self.tabBarController工作?這不是我的財產。是因爲我在UITabBarController裏面還是什麼?謝謝你:-) – Erez
就像在根視圖以外的視圖中訪問navigationController一樣,即使你還沒有爲navigationController聲明屬性。你可以從實際上在tabBarController中的viewController訪問tabBarController。 – sElanthiraiyan
非常感謝:-) – Erez