从模态视图控制器中打开UIImagePickerController

时间:2011-02-15 21:39:44

标签: iphone

我正在尝试向用户呈现图像选择器,同时它们位于以模态视图呈现的视图上。

我正在桌面视图应用中构建视图。现在代码运行但不打开ImagePicker。

在DetailTableViewController.m

@implementation DetailTableViewController

导航中有一个(+)按钮,当点击它时我打电话

- (void)add
{
  DetailTableViewController *controller = [[DetailTableViewController alloc]
                                  initWithStyle:UITableViewStyleGrouped];    

UINavigationController *newNavController = [[UINavigationController alloc]
                                            initWithRootViewController:controller];
newNavController.delegate = self;

[[self navigationController] presentModalViewController:newNavController
                                               animated:YES];

DetailTableViewController *controller2 = [[DetailTableViewController alloc]
                                         initWithStyle:UITableViewStyleGrouped];    
imgPicker = [[UIImagePickerController alloc]
                                      initWithRootViewController:controller2];
imgPicker.allowsEditing = YES;
imgPicker.delegate = self;      

//______________HERE I CREATE THE INTERFACE FOR THIS VIEW IN CODE__________________

    NSLog(@"Load add View");
 }

此页面上的一个按钮是选择图像按钮,位于:

   - (IBAction)grabImage {
        [newNavController pushViewController:imgPicker animated:YES];
    NSLog(@"grabImage");
    }

这不会显示imgPicker视图。但是会记录按钮单击。

我在文件顶部:DetailTableViewController.m

@implementation DetailTableViewController

@synthesize imgPicker;

在DetailTableViewController.h中

 @interface DetailTableViewController : UITableViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate> {
    MWFeedItem *item;
    NSString *dateString, *summaryString;
    IBOutlet UIWebView *webview;
    IBOutlet UIButton *dismissViewButton;
    UIImagePickerController *imgPicker;
    UINavigationController *newNavController;
    IBOutlet UIButton *upload;
    IBOutlet UIButton *doneEdit;
    IBOutlet UIImageView *image;
}

如何制作imgPicker? 我试过了:

  • 使用presentModalViewController而不是push in grabImage
  • 列出项目的控制器imgPicker的许多组合。和一些 我收到错误:(应用程序试图在目标上显示一个nil模态视图控制器)
  • 这个问题的几个变种:​​
    iPhone modal view inside another modal view?

更新包括@aBitObvious的更正,但问题仍然存在。

1 个答案:

答案 0 :(得分:1)

@aBitObvious指出了我的答案。本地覆盖结果是答案,但不是在imgPicker上,而是在newNavController上。

再次感谢!