首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >performSegueWithIdentifier不工作

performSegueWithIdentifier不工作
EN

Stack Overflow用户
提问于 2012-05-06 02:14:05
回答 1查看 11.1K关注 0票数 3

我有这个代码,当一个按钮被按下时,它加载一个新的UIView (从故事板)。在按下按钮时触发goPressed函数,并调用selectImage函数。selectImage打开一个UIImagePickerController,让用户选择一张照片。用户选择照片后,didFinishPickingMediaWithInfo代理将选择的图像添加到UIImageView。

在“goPressed”中,在执行selectImage之后,它应该在like上执行一个段,注释为//1。但什么也没有发生。performSegueWithIdentifier似乎不起作用。如果我在调用performSegueWithIdentifier之前没有调用self selectImage,它就可以工作。代码如下:

代码语言:javascript
运行
复制
- (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不能工作?我希望我没有遗漏你需要的任何信息。

EN

回答 1

Stack Overflow用户

发布于 2012-05-06 03:06:08

我假设你试图分割到的视图使用的是你在分割之前得到的图片?如果它们从图像拾取器中取消,您是否仍要分割?

如果它需要图片,那么也许你应该在委托调用“完成挑选”之后调用你的segue。

segue未触发的问题可能是由于动画仍在此处发生:

代码语言:javascript
运行
复制
[[picker presentingViewController] dismissModalViewControllerAnimated:YES];

您可以尝试:

代码语言:javascript
运行
复制
[[picker presentingViewController] dismissModalViewControllerAnimated:NO];

或者,如果你想保持动画效果,把这个片段移到"picker did finish“方法中,然后这样做:

代码语言:javascript
运行
复制
[self dismissModalViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"lastView" sender:self];
}];

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

代码语言:javascript
运行
复制
//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视图中滑动,暂停使过渡看起来很自然。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10464638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档