Duplicate Views

I want to create a view with some controls inside, a text box and some buttons, and I want to duplicate it to show them as tab contents as tabs. Each tab must have an instance of this view. Directions?

+3
source share
3 answers

Dave DeLong is close, and your question contains the answer ("each tab must have an instance of the view"). Subclass the UIViewController to program view creation or load the NIB. Then create several instances of your subclass of UIViewController and add them all to the UITabViewController viewControllers property.

You will want to spend some time using the View Controller Programming Guide . The fact that you are making multiple instances of the same subclass of UIViewController actually has little effect on the solution.

+5
source

Umm ... I'm not quite sure if I understood correctly what you would like to do. The word "duplicate" does not sound very good, because most often when programming it indicates a "smell".

I am not a specialist from cocoa, nor from objective-c, but I think you could somehow put your controls in some container control and create an instance (reuse, not duplication) of this container control in the view tabs or wherever you wish.

+1

A quick and dirty way to clone a presentation hierarchy is to encode and decode it. Example:

NSData * encodedView = [NSKeyedArchiver archivedDataWithRootObject:myView];
NSView * myViewClone = [NSKeyedUnarchiver unarchiveObjectWithData:encodedView];
0
source

Source: https://habr.com/ru/post/1712607/


All Articles