认为不能正常工作

时间:2014-02-03 17:03:26

标签: ios objective-c uistoryboard uistoryboardsegue

我正在尝试让我的“主视图”允许用户选择一张照片并将其显示在我的“第二视图”上。到目前为止,当按下按钮时,它允许用户选择照片并将其设置为imageView,但是当我尝试使其进入不同的视图时,我会遇到问题。这是我用户选择按钮的代码和底线是我试图用来切换视图的。

- (IBAction)usePhotos:(id)sender {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =
    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
    imagePicker.allowsEditing = YES;
    [self presentViewController:imagePicker animated:YES completion:nil];
    _newMedia = NO;
    [self performSegueWithIdentifier:@"switch" sender:self];
}

我也尝试了不同的方式,他们也没有工作,所以我很困难。提前谢谢!

1 个答案:

答案 0 :(得分:1)

据我了解你,你需要先拿起图像。一旦你有了一个,你想在第二个视图上显示它。 如果这是正确的,您的代码将无法工作,因为您提供了图像选择器,并且您希望在同一时间执行segue。尝试移动线:

[self performSegueWithIdentifier:@"switch" sender:self];

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *image = info[UIImagePickerControllerEditedImage];

    // If you want to dismiss this view animated you should perform segue with delay (0.5 should be enough)
    [picker dismissViewControllerAnimated:NO completion:NULL];
    // You pass an image as a parameter so you can access it in prepareForSegue: method and you can pass it to destination view
    [self performSegueWithIdentifier:@"switch" sender:image];

}