Note: I'm not talking about master-split split footage!
There is a question similar to this (), but the question only refers to standard features, not the layout itself. In addition, the answer will only show how to avoid duplicate code, but you must link the IBActions to each view. Perhaps we can expand the linked question and find a better solution: -)
Therefore, I would like to define a master page for all the visuals / view controllers of my app. For example, there is a general task in web development (i.e.).
The master page contains the actual layout (background color, where the title goes, where content goes) and there are standard features in it
interface builder (with or without storyboard) ), What would be the best way to accomplish this?
All views (open menu, back, open support page etc.)
Here are my thoughts:
Option 1:. For standard features, the subtype UIViewController, common layout copypaste
in every view / ViewController: easy to use, easy to use, just copy all the controls, set parent class in IB And connect the standard feature button.
Damage: If you have loads of scenes, you can easily forget to connect to standard features. If for any reason the master layout changes, you are trapped for
Option 2:. Subclass UIViewController is anywhere in the form of a layout program, viewDidLoad
, where you also add target to the setup event.
Both layouts and features are handled in one place and are easily unstable.
Disadvantages: Whatever you need to setup layout program is inconsistent if you use IB everywhere you have master layout in IB Are not watching, so you should "visualize" while configuring all other views in the IB. Without the storyboard, you can use the XIB only to design the content scene, but then you do not have "complete picture" in the IB. Apart from this, it does not work with storyboards.
Both options do not look very beautiful to me. What is your attitude to doing this (this has become a common issue!)?
One of the ways to do this is to follow the two favorite methods of bunch.
In both of them, you start masterwatch (using your word) and design all the layouts for general elements. Then for content view, either:
- Put it in a separate view, and add childViewControllers programmatically; Or
- Put in a container vee that has UICollectionView. Create a cell in the archive that will see the entire collection. Create a custom cell class with an outlet (in the pageview, in my example) and load the ViewControllers in two ways with the storyboard. Either set your VC's identifiers to those numbers that show that they will look in the archive, or create an array of VC names. After this, whenever a user goes to a certain Vice Chancellor, you will be asked to scroll to the index of collectionVC
Implementation in cellForItemAtIndexPath will look something like this.
- (UICollectionViewCell *) collectionView: (UICollectionView *) collectionView cellForItemAtIndexPath: (NSIndexPath *) indexPath {AMMasterCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier: @ "cell" forIndexPath: indexPath]; (View view in cell) [see viewFromSuperview]; NSString * viewID = self.arrayOfViewControllerNames [indexPath.item]; AMMasterViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier: viewID]; AMMasterView * pageView = (AMMasterView *) viewController.view; [Add Cell.pageView SUBview: Pageview]; [Add self childview controller: view controller]; [ViewController didMoveToParentViewController: Self]; Return cell; }
I did this many times, and it works beautifully.
Comments
Post a Comment