[英]How to Passing Uiimage from one view controller to Other view controller when using push view controller used?
I Have three View controllers. 我有三个View控制器。
First UIViewController contain one UIImage
, when I click "crop" button, go to second view controller I pass the image by push view controller, here I'am cropping my UIImage
. 第一个UIViewController包含一个
UIImage
,当我点击“crop”按钮时,转到第二个视图控制器我通过推视控制器传递图像,这里我正在裁剪我的UIImage
。 In second UIViewController
which is inherited from image editor Viewcontroller after cropping my image, clicking "done" button. 在裁剪图像后继承自图像编辑器Viewcontroller的第二个
UIViewController
中,单击“完成”按钮。
I need to pass the cropped image to another view controller where i am having share button to share the post. 我需要将裁剪的图像传递给另一个视图控制器,我在其中分享按钮来分享帖子。
Problem is when I am puishing the editted image to another view controller in which share button is present,image is not passing. 问题是当我将编辑的图像推到另一个存在共享按钮的视图控制器时,图像没有通过。
You are saving the image in the Detail Controller before you make the push? 在进行推送之前,您是将图像保存在Detail Controller中?
DetailController *detailVC=[[DetailController alloc]
initWithNibName:@"DetailController"
bundle:nil];
detailVC.image = self.image;
[self.navigationController pushViewController:detailVC animated:YES];
Delegation 代表团
You implement the protocol on your View Controller
您在
View Controller
上实现协议
In Controller.h
: 在
Controller.h
:
@class Controller;
@protocol ControllerDelegate <NSObject>
- (void)sendFrom:(Controller *)controller
image:(UIImage *)image;
@end
@interface Controller : UIViewController
@property (weak, nonatomic) NSObject <ControllerDelegate> * delegate;
@end
In Controller.m
when you want send the image: 在
Controller.m
当您想要发送图像时:
[self.delegate sendFrom:self
image: self.image];
After on your Detail View Controller
, don't forget to assign it as delegate of the Controller
. 在
Detail View Controller
,不要忘记将其指定为Controller
委托。 And to implement the ControllerDelegate
protocol. 并实现
ControllerDelegate
协议。 To do that: 要做到这一点:
In your DetailController.h
implement the protocol. 在您的
DetailController.h
实现协议。 You can do that on your .m as well. 您也可以在.m上执行此操作。
#import "Controller.h"
@interface DetailController : UIViewController <ControllerDelegate>
You keep a reference of the Controller
in The Detail Controller
您将在
Detail Controller
保留Controller
的参考
@property (nonatomic, strong) ViewController *controller;
And assign its delegate
in the viewDidLoad
of the Detail Controller
. 并在
Detail Controller
的viewDidLoad
中分配其delegate
。 For example: 例如:
-(void)viewDidLoad:(BOOL)animated{
[super viewDidLoad:animated];
self.controller.delegate = self;
}
Don't forget to implement the protocol method
in your Detail View. 不要忘记在详细信息视图中实现
protocol method
。 Here you receive the image you passed from Controller and you save it in your Detail Controller
UIImage
property: 在这里,您将收到从Controller传递的图像,并将其保存在
Detail Controller
UIImage
属性中:
- (void)sendFrom:(Controller *)controller
image:(UIImage *)image{
self.image = image;
}
You can implement storyboard segue to your detail controller and use following sample code. 您可以将storyboard segue实现到您的详细控制器并使用以下示例代码。
- (void)cropButtonClick:(id)sender
{
[self performSegueWithIdentifier: @"MySegue" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"MySegue"]) {
DetailController *detailVC = segue.destinationViewController;
[detailVC setImage:self.image];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.