Ravi
Ravi

Reputation: 888

How to get duplicate UIScrollView from exsisting UIScrollView?

how can i get duplicate UIScrollView from existing UIScrollView without disturbing it.

first scrollview,

UIScrollView *firstScrollView;

second scrollview,

UIScrollView *duplicateScrollView = [[UIScrollView alloc] init];
[self.view addSubview:duplicateScrollView];
duplicateScrollView.backgroundColor = [UIColor clearColor];

duplicateScrollView = firstScrollView.copy;

getting crash.

actually i want to do changes in duplicateScrollView but that changes will not effect in firstScrollView.

Please suggest me. Many Thanks.....

Upvotes: 1

Views: 114

Answers (1)

Istvan
Istvan

Reputation: 1627

UIScrollView does not conform to the Copying protocol therefore you cant use the copy method on it. What you can do is to archive and unarchive it and this should give you a deep copy of a view:

id copyOfView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:firstScrollView]];

Upvotes: 2

Related Questions