gpt4 book ai didi

ios - Segue 无法正常工作

转载 作者:行者123 更新时间:2023-11-29 03:17:24 25 4
gpt4 key购买 nike

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

- (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];
}

我也尝试过不同的方法,但它们都不起作用,所以我很困惑。预先感谢您!

最佳答案

据我了解,您需要首先拾取图像。一旦你有了一个,你想在第二个 View 上显示它。如果这是正确的,您的代码将无法工作,因为您呈现图像选择器并且您想要同时执行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];

}

关于ios - Segue 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21533198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com