我正在编写一个iOS应用程序,在视图中有一个按钮。单击该按钮可获得一个操作表,其中包含从相机或图库中选择图像的选项。拾取图像后,应通过手动调用segue将其传递到另一个视图。出现图像选择器并执行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 :(得分:2)
听起来你正在执行一个样式为push
的segue而不在UINavigationController
内。
当您致电performSegueWithIdentifier:sender:
时,它首先正确调用prepareForSegue:sender:
然后它会尝试检索当前的导航控制器并推送目标控制器执行类似
[self.navigationController pushViewController:destinationController animated:YES];
但由于您不在UINavigationController
内,因此navigationController
属性设置为nil
,导致上述调用无声地失败。
将segue的显示样式更改为push
以外的其他内容(例如modal
)或将控制器嵌入UINavigationController
。