Reputation: 14557
I have an app where I have an imageview displayed within a UIView that the user has scaled and moved around, and I'd like to pass this exact same imageview to the next UIViewController that gets pushed onto the navigation stack. What is the best way to go about doing this? Do I have make some sort of deep copy?
Upvotes: 0
Views: 161
Reputation: 23540
Give the view reference to the next controller, retaining it.
You could have some problem to deal with its bounds or frame, but if you just want the same, that should be ok.
In the new controller, get that passed view and add it as a subview of your main view. Don't forget at the end to remove it from its superview, and to release it before returning to the previous controller.
Upvotes: 0
Reputation: 299455
controller.imageView = imageView;
There's not much special about this. The only thing you need to do is to add the view to your view hierarchy. Views can only have a single superview, so when you add it to a new view hierarchy, it is automatically removed from the old view hierarchy. The only tricky thing is when you pop back up the stack. Do you expect the view to still be available in the old view controller? (It won't be.)
In general, I'd tend to recommend passing the parameters rather than the actual view (i.e. the image and its transform). This gets rid of any issues going up or down the stack, but either way can work.
Upvotes: 2