在一个UIViewController中获得了一张Image,怎么传递给需要切换的另一个UIViewController中。
这里用一种简单的方法,感觉比用协议之类的方便一些。
1.在第一个UIViewController(FirstViewController)声明一个UIImage变量。
在FirstViewController.h中:
@property(nonatomic,retain)UIImage *pickedImage;
在FirstViewController.m中:
@synthesize pickedImage;
2.将需要传递的Image图像赋值给pickedImage.
3.在第二个UIViewController中同样声明一个UIImage变量。
4.切换到第二个UIViewController。
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
secondView.pickedImage = pickedImage;
[self presentViewController:secondView animated:YES completion:nil];
这样在第二个ViewController中pickedImage就是需要的Image。