How to use segue to pass taken photo

冷暖自知 提交于 2020-01-07 07:45:09

问题


I want to pass a photo taken in the first view controller to a second view controller. I want the user to take the photo in the first view controller and then crop in in the second view controller and then save.. So its like.. User take photo→crop→save. I just want to do this simple task but taking me days to get the segue go right.. Is segue the best way to do this? or is there a more easier way to do this task. I am a beginner in objective -c so its making me confused with segues and all the stuff.


回答1:


You need to implement prepareForSegue:sender: in the source view controller. This will give you access to the destinationViewController via the passed storyboard. Then you can set the image so its available when the destination view controller is displayed.




回答2:


As far as segue is concerned you need to create a segue arrow using storyboard by dragging arrow from first view controller to second view controller, and most importantly you need to give the segue an identifier or name.

For firing you segue you may do it programatically, like:

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

For handling things when segue is fired you need to write prepareForSegue() method, you may pass any object from current viewController to next viewController:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"ShowSecondScreen"])
    {
        SecondViewController *secondViewController = segue.destinationViewController;
    secondViewController.imageObj = image;
    }
}


来源:https://stackoverflow.com/questions/17740424/how-to-use-segue-to-pass-taken-photo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!