2012-12-04 19 views
1

我正在寫一個iOS應用程序,在視圖中有一個按鈕。點擊該按鈕會得到一個操作表,該操作表具有從相機或圖庫中選擇圖像的選項。在圖像被選中後,它應該通過手動調用一個segue傳遞給另一個視圖。圖像選擇器出現並執行準備執行的代碼,但不會出現代碼。有沒有錯誤,我已經檢查的所有標識符等。這裏是代碼:Segue沒有出現在圖像選取器後

-(IBAction)showButtonClicked:(id)sender { 
    UIActionSheet *photoActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from Library", nil]; 
    photoActionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
    [photoActionSheet showInView:self.tabBarController.tabBar]; 
} 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

    switch (buttonIndex) { 
    case 0: 
      { 
      [self dismissModalViewControllerAnimated:YES]; 
      UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
      picker.delegate = self; 
      picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
      [self presentModalViewController:picker animated:YES]; 
      break; 
      } 
     case 1: 
      { 
      [self dismissModalViewControllerAnimated:YES]; 
      UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
      picker.delegate = self; 
      picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      [self presentModalViewController:picker animated:YES]; 
      break; 
      } 
    default: 
      break; 

    } 

} 



- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

    if ([segue.identifier isEqualToString:@"goToPhotoDetails"]){ 
     FostoPhotoDetailsViewController *photoDetails = (FostoPhotoDetailsViewController *)segue.destinationViewController; 
     photoDetails.imageView.image = self.buttonImage1; 
    } 
} 



- (void) imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
        editingInfo:(NSDictionary *)editingInfo 
{ 

    self.buttonImage1 = image; 
    //FostoPhotoDetailsViewController *photoDetails = [[FostoPhotoDetailsViewController alloc] init]; 
    //photoDetails.imageView.image = image; 
    [self dismissModalViewControllerAnimated:NO]; 
    NSLog(@"Test"); 
    [self performSegueWithIdentifier:@"goToPhotoDetails" sender:self]; 
} 
+0

你的segue是如何配置的? –

回答

2

聽起來像你執行與風格push一個不賽格瑞是一個UINavigationController內。

當你調用performSegueWithIdentifier:sender:它首先正確地調用prepareForSegue:sender:然後它試圖檢索當前導航控制器和推動目標控制器做這樣的事情

[self.navigationController pushViewController:destinationController animated:YES]; 

但因爲你不是UINavigationController裏面的屬性navigationController設置到nil,導致上述呼叫靜默失敗。

要麼將​​您的segue的顯示樣式更改爲push(例如modal)以外的內容或將您的控制器嵌入UINavigationController中。

+0

謝謝!這是問題所在。現在正在工作。雖然我想傳遞給第二個視圖的圖像仍然不顯示。 – apr

+1

在該特定問題上打開另一個問題,我很樂意爲您提供幫助 –