【问题标题】:Segue not working correctlySegue 无法正常工作
【发布时间】:2014-02-03 17:03:26
【问题描述】:

我正在尝试让我的“主视图”允许用户选择一张照片并将其显示在我的“第二视图”中。到目前为止,当按下按钮时,它允许用户选择照片并将其设置为 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];
}

我也尝试了不同的方法,但它们也没有奏效,所以我很困惑。提前谢谢!

【问题讨论】:

    标签: ios objective-c uistoryboard uistoryboardsegue


    【解决方案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];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-05
      • 1970-01-01
      • 2016-10-04
      • 2012-04-01
      • 2016-12-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      相关资源
      最近更新 更多