使用UIImagePickerController更正UINavigation层次结构

时间:2011-06-17 19:17:33

标签: iphone ios4

我有一个标签栏+基于导航的应用程序,我想从主UIViewController的右侧导航按钮背靠背启动两个视图,而没有太多明显的转换。我无法找到正确的结构和包含这种导航方案的方法。

我需要显示的第一个视图/控制器是UIImagePickerController,它必须显示为模态。如果您尝试将其推送到UINavigationController,您将获得异常。一旦选择器被解雇,我想展示一个孩子UIViewController。当这个子控制器被解雇时,我将返回显示带有选项卡的主UIViewController。

以下是我现在的结构:

Tab Bar 
   -> (tab 1) UINavigationController -> UIViewController (main content for tab 1)
   -> (tab 2) UINavigationController -> UIViewController (main content for tab 2)

MainContent1Controller:

- (void)onNavigationItemTapped {

  // Launch the picker to take pictures
  UIImagePickerController *picker = [[UIImagePickerController alloc] init];

   // configure picker options including:
  picker.delegate = self;

  [self presentModalViewController:picker animated:YES];
  [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Process the photo taken

    // unlink this view controller as the delegate
    picker.delegate = nil; 

    // Dismiss the UIImagePickerController 
    [self dismissModalViewControllerAnimated:YES];                          

    // Create the 2nd controller and show - this doesn't work and the child controller is not visible for some reason
    ChildController *child = [[ChildController alloc] initWithNibName:...];
    [self presentModalViewController:child animated:YES];
    [child release];
}   

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你应该这样做,

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Process the photo taken

    // unlink this view controller as the delegate
    picker.delegate = nil; 

    // Create the 2nd controller and show - this doesn't work and the child controller is not visible for some reason
    ChildController *child = [[ChildController alloc] initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:child animated:NO];
    [child release];

    // Dismiss the UIImagePickerController 
    [self dismissModalViewControllerAnimated:YES];                          
}   

这样您就可以将child添加到导航层次结构并关闭图像选择器。单个动画将显示图像选择器被解除以显示child控制器。