2011-02-15 51 views
1

我試圖在呈現爲模態視圖的視圖上呈現圖像選擇器給我的用戶。從模態視圖控制器中打開UIImagePickerController

我在建立表視圖應用程序的視圖。現在代碼運行但不打開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,而不是推入grabImage
  • 列表項,其中控制器imgPicker呈現給許多組合。對於一些 我得到的錯誤:(應用程序試圖把目標一零模態視圖控制器)來自這個問題
  • 幾個變化:
    iPhone modal view inside another modal view?

修訂包括@aBitObvious更正,但問題依然存在。

+0

你有`imgPicker` ivar,但是在`add`方法中,你聲明瞭一個_local_變量和_local_變量(不是ivar)相同的名稱和alloc + init。同樣在`add`中,爲什麼要調用`[super viewDidLoad];`? – Anna 2011-02-15 22:01:59

回答

1

@aBitObvious指出了我的答案。本地覆蓋原來是答案,但不是在imgPicker上,而是在newNavController上。

再次感謝!

相關問題