performSegueWithIdentifier不工作(performSegueWithIden

2019-06-24 04:45发布

我有这样的代码,当按下一个按钮,加载一个新的UIView(从故事板)。 goPressed功能按钮按下发射并呼吁selectImage功能。 selectImage打开的UIImagePickerController,让用户选择一张照片。 用户已经选择了照片之后,didFinishPickingMediaWithInfo代表所选择的图像添加到一个UIImageView。

在“goPressed”中,进行后selectImage,应当执行在像Segue公司评论作为// 1。 但没有任何反应。 performSegueWithIdentifier似乎并不奏效。 如果我不叫performSegueWithIdentifier之前调用[自我selectImage],它的工作原理。 下面是代码:

- (IBAction)goPressed:(id)sender {
    [self selectImage];
    [self performSegueWithIdentifier:@"lastView" sender:currentSender]; //1
}
-(void)selectImage
{
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

    // Delegate is self
    imagePicker.delegate = (id)self;

    // Allow editing of image ?
    imagePicker.allowsEditing=NO;


    // Show image picker
    [self presentModalViewController:imagePicker animated:YES];


}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [[picker presentingViewController] dismissModalViewControllerAnimated:YES];


    lePreview.image= image;


}

请帮帮忙,为什么performSegueWithIdentifier不工作? 我希望我不想你需要的任何信息。

Answer 1:

我假设你做你的赛格瑞之前您试图将视图原因请看使用你的图片? 如果他们从图片选择取消你还是要Segue公司?

如果需要的图片,那么也许你应该委托通话“并完成采摘”后,打电话给你SEGUE。

与SEGUE不触发原因可能是从这里仍然发生动画问题:

[[picker presentingViewController] dismissModalViewControllerAnimated:YES];

你可以试试:

[[picker presentingViewController] dismissModalViewControllerAnimated:NO];

或者,如果你想保持的动画,移动SEGUE到“选择器没有完成”的方法,并做这种方式:

[self dismissModalViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"lastView" sender:self];
}];

或者,如果不起作用尝试在pickerdidfinish方法(该方法注意 - 这应该是实现为调用模式视图,而不是模式视图本身的控制器的委托:

//maintain the animation
[self dismissModalViewControllerAnimated:YES];

//slight pause to let the modal page dismiss and then start the segue
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

    //code to be executed on the main queue after delay

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

});

我经常使用这一过渡,它使一个很好的降摒弃了模态视图,然后滑动在SEGUE视图和暂停允许过渡很自然。



文章来源: performSegueWithIdentifier not working