The facebook view of the left slide bar should appear in all view controllers

In my first view of the iphone app, I implemented a Facebook type slide bar layout. Now I want to implement this on all view (screen) controllers in the application, means that regardless of the view, the left slide bar should appear when the menu button is clicked at the top in all views.

My app contains 25-30 viewcontrollers and my slider layout needs to appear in all views.

Can anyone suggest how I can include above FB Layout in all views

Thank you in advance

Frame

+3


source to share


4 answers


I had the same problem. I was using facebook style menu and needed it in all view controllers.

You can use the Container Controller. The container controller can have a basic layout that I have defined in a nib containing a navigation bar and a bar button element to toggle the menu and then add child controllers and remove them as needed. This way you can throw whatever view controller you want into the container controller and it will render it.

You can also add gesture controls to open / close menus easily.

You will need to make the container controller yourself, it is not standard. I think this is a better solution than inheritance because if you are using inheritance you cannot create for example UITableViewController, all your controllers will be of yuor master class type. You can of course fix this with delegates.



It may sound a little tricky, but see this tutorial I used: http://www.cocoanetics.com/2012/04/containing-viewcontrollers/

It wasn't that hard.

EDIT: you can just use UINavigationController. Just set the base view controller to the view controller you want to display and you can prevent it from adding a back button etc. To the navigation bar, overriding the default methods. Make UINavigationController like rootNavigationController

. It might be easier.

+3


source


A simple, one view controller in which you have implemented FB layout

and run. Make it a base class on top UIViewController

. For the rest of the ViewControllers, inherit from the MasterClass you created. Doing so will result in a swipe gesture that will open a slider for all of your 30 controllers.

EDIT

See you we have a UIViewController, now you first subclass UIViewController: let's say FBViewController. In this FBViewController, you implement FBLayout in such a way that swipes and everything works. only this FBViewController as rootViewController and checks all functionality. When everything works fine, grow on it. I mean this.

Suppose you are creating a tabbed application in which all three tabs must have the same FBLayout style. Then follow these steps.



  • Create an FBViewController, it inherits from UIViewController (using UIViewController subclass template, also check the generate XIB button) also has an XIB for it FBViewController.XIB (fully implements FBLayout in it.This will be your base class)

  • Then again create three more ViewController classes (FirstViewController, SecondViewController, ThirdViewController) from the UIViewController subclass template, but for these three, don't check the generate XIB button. these three will use the XIB of the base class FBViewController (if you are wondering how to do this, skip to step 3 :))

  • Go to the header file of the FirstViewController class you created, there you can see @interface FirstViewController: UIViewController

    replace it with @interface FirstViewController: FBViewController

    , but before importing FBViewController.h into the header file. Repeat the same for the other two classes - SecondViewController, ThirdViewController. As these three will inherit from FBViewController. They viewDidLoad

    [super viewDidLoad]

    will be loaded FBViewController and generate performance. after the line, [super viewDidLoad];

    you can implement your own ur methods.

  • In the three classes, just change the method initWithNibName

    to change the name and title of the tab bar.

  • In appDelegate go to method didFinishLaunching

    and put these three view controllers in tabBarController

    , set tabBarController

    as rootViewController.

And we are done. If yours FBViewController

works fine. You will see that all three classes behave the same. Thanx to the power of Inheritance.

Cheers, play a little, have fun.

+4


source


I would highly recommend using an open source solution that handles all edge cases for you - this is the simplest, most reliable and user-friendly (as the community will keep it up to date). ViewDeck seems to be the most popular solution though I also had PPRevealSideViewController success... Both provide a very robust implementation that takes a long time to do yourself (for example, you can optionally activate scrolling on the navigation bar or even content area to open the menu). Also, they decouple the slide logic and the open menu (which can be any view controller you like, but most likely a table view controller) from your other view controllers. So any view manager can have a side menu without duplicating any code - the separation of concern is great :)

+2


source


You can create SharedInstance for the SideView class. I am doing the same for iAD to show the application. See the iAdSuite link where BannerViewController is SharedInstance so they are easy to use for all View Controller

http://developer.apple.com/library/ios/#samplecode/iAdSuite/Listings/TabbedBanner_TabbedBanner_BannerViewController_m.html

+1


source







All Articles