Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mpramodjain

macrumors regular
Original poster
Nov 20, 2008
152
0
Banglore
Can it be possible to clone/copy an UIView object, without using Archivers.

for a scenario, I have the same kind of view that needs to be shown on the different controllers. So, what I thought was if there is any other way to clone it before initializing then, it would be better to play without creating alloc for each UIView of same replicaa.
 
You could put the UIView into its own .xib, preload the .xib using UINib's nibWithNibName:bundle: and then call instantiateWithOwner:options: as necessary. Would that work for you?
 
You could put the UIView into its own .xib, preload the .xib using UINib's nibWithNibName:bundle: and then call instantiateWithOwner:options: as necessary. Would that work for you?

Jimi,,, thanks for your quick reply..

Am not using IB.. through programmatically, am creating a UIView and want to use it..
 
Am not using IB..

UIView doesn't conform to the NSCopying protocol to the copy method inherited from NSObject isn't going to be functional AFAIK.

It does implement UICoding, so I think using archivers might be the only way.

However, could you archive once and unarchive multiple times?
 
Look up NSCopying and copyWithZone. If you implement these for your UIView subclass then that should work. Alternatively you can implement a simple utility method that returns a copy of your UIView subclass. It will copy those properties that you think are important. The code would be about the same as an implementation of copyWithZone.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.