Monday, May 20, 2013

UISplitViewController Landscape

Tutorial Request from Mazrizan Kamisan

We'll have the portrait view in another tutorial which will be a continuation of this landscape tutorial of UISplitViewController.

/*Note: This works in OS versions greater than or equal to iOS 6.0
OS versions less than iOS 6.0 has a different look in its UIPopoverController and doesn't support Landscape Orientation.*/

I studied UISplitViewController by creating a Master Detail Application Template. For sure, you will also be able to understand by looking at its code. For those who want to do it themselves (not just merely creating a Master Detail Application), just follow this tutorial.

1. Create an Empty Application Template.

Select iPad for our Device Family.

2. Add a New File, subclass of UITableViewController, check "With XIB for user interface." This is the view on the left area of our application.

3. Create another File, subclass UIViewController. This is for the bigger area (right panel) of our application. I named it "Detail" view because it acts and shows the detailed view of the cell selected in our tableview (left area).

4. Create a UISplitViewController property in our AppDelegate.h file.

Synthesize the splitViewController property and import the two new files we created from steps 2 and 3 in AppDelegate.m file.

5. Go to AppDelegate.m file and update the didFinishLaunchingWithOptions method such that:
  • Create an instance of the two new classes we created.
  • Allocate and initialize the splitViewController.
  • Set the view controllers of our splitViewController.
    • @[menuVC, detailVC] is just the same as saying [[NSArray alloc] initWithObjectsmenuVCdetailVC, nil];
  • Set the rootViewController of our window to splitViewController.


Hit Run button and you should see something like this.

6. Open PopMenuViewController.h and create a PopMenuDetailViewController property. This will be our "link" to the two view controllers.
Open PopMenuViewController.m file and synthesize the PopMenuDetailViewController property. Also, create an array for our the list that we will be showing in our tableView.

7. Add objects in our array inside our ViewDidLoad method in PopMenuViewController.m file.
self.menu = [[NSArray alloc] initWithObjects@"Menu 1", @"Menu 2"@"Menu 3"];

Update the Table view Data Source methods such that:
  • numberOfSections = 1
  • numberOfRows = array.count
  • cellForRowAtIndexPath >> cell Label will be from our array


8. Open PopMenuDetailViewController.xib file and add a UILabel at the middle of the view. Create an IBOutlet property of the UILabel and connect them.
@property (nonatomic, strong) IBOutlet UILabel *passedObjLabel; // Interface Section
@synthesize passedObjLabel; //Implementation Section




9. Make a function that will update the contents in our Detailed view depending on what was selected from our tableview. For now, let's have a very simple content such as NSString.
- (void)updateMenuLabel:(NSString *)passedObject {
    if (![self.passedObjLabel.text isEqualToString:passedObject]) {
        self.passedObjLabel.text = passedObject;
    }
}

Call this method in our viewDidLoad. You may choose whatever string you want to pass as a default value.

10. In our PopMenuViewController.m file, update table view's delegate method didSelectRowAtIndexPath. This will update the detailed view.
[self.detailViewController updateMenuLabel: [menu objectAtIndex:indexPath.row]];

Hit Run! Make sure you have your simulator in landscape. (If it's in portrait, press CMD + Left key)


But wait! There's more!

How come there's no Navigation Bar on top? I want one!

That's simple! Just edit didFinishLaunchingWithOptions method in our AppDelegate.m. And add a self.title@"My Title" in the initialization function in our Menu and Detailed view controllers. You may also change the tint color of our Navigation Bar according to your preference, add navigation buttons, etc.

Hit Run! 



Download sample code here.

Follow me on my new Twitter Account: @iosmadesimple

25 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. ThnQ so much Dude you really helped a lot because there is no such a good tutorial even in raywendarlitch its really simple and amazing to use and learn
    thanQ so much n thnQ again
    It proved its name really it is making iOS simple

    ReplyDelete
  3. From your detail view how to navigate to other pages using a button or something so the navigation happens within the detail view and the master view stays the same. How can i achieve it any idea?

    ReplyDelete
  4. Plz help me...


    I have just created a new "empty application" project I Xcode 5.

    and i used split viewcontroller

    Then on my TableView Controller, I have added up a few items: Home, View 1, View 2.

    I have removed the default databinding, so when i run it now it appears as intended.

    As default my "Home" view is my Detail View Controller.

    Now I would like: When i press "View 1" it changes my Detail View Controller to a new view I have created on my xib.

    But how do I do that?

    I have tried to push in my "View 1" but then i first have to go back to my Detail View, before I can get the menu to show up...

    I guess I have to make my "View 1" the root controller?

    ReplyDelete
  5. Hi this is Kathiresan i am having 3 years of experience as a dot net developer and i am certified. i have knowledge on OOPS concepts in .NET but dont know indepth. After learning android will be enough to get a good career in IT with good package? and i crossed Android Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

    Thanks,
    kathiresan

    ReplyDelete
  6. Hi this is Kathiresan i am having 3 years of experience as a dot net developer and i am certified. i have knowledge on OOPS concepts in .NET but dont know indepth. After learning android will be enough to get a good career in IT with good package? and i crossed Android Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

    Thanks,
    kathiresan

    ReplyDelete
  7. Hi this is vignesh i am having 3 years of experience as a android developer and i am certified. i have

    knowledge on OOPS concepts in android but dont know indepth. After learning hadoop will be enough

    to get a good career in IT with good package? and i crossed hadoop training in

    chennai
    website where someone please help me to identity the syllabus covers everything or not??
    Thanks,
    vignesh

    ReplyDelete
  8. Hi, this is Ganesh I am having 3 years of experience as a Dot Net developer and I am certified. I have Knowledge on OOPS Concepts in .NET indepth. After learning Salesforce will be enough to get a good career in IT with good Package? and i crossed Salesforce Training in Chennai website where someone please help me to identify the syllabus covers everything or not??

    Thanks,
    Ganesh

    ReplyDelete
  9. Hi, this is Ganesh I am having 3 years of experience as a Dot Net developer and I am certified. I have Knowledge on OOPS Concepts in .NET indepth. After learning Salesforce will be enough to get a good career in IT with good Package? and i crossed Salesforce Training in Chennai website where someone please help me to identify the syllabus covers everything or not??

    Thanks,
    Ganesh

    ReplyDelete

  10. Hi this is abinaya i am having 3 years of experience as a java developer and i am certified. i have knowledge on OOPS concepts in java but dont know indepth. After learning oracle will be enough to get a good career in IT with good package? and i crossed Oracle Training in Chennai website where someone please help me to identity the syllabus covers everything or not??

    Thanks, abinaya

    ReplyDelete
  11. Hi this is abinaya i am having 3 years of experience as a java developer and i am certified. i have knowledge on OOPS concepts in java but dont know indepth. After learning oracle will be enough to get a good career in IT with good package? and i crossed oracle training chennai website where someone please help me to identity the syllabus covers everything or not??

    Thanks, abinaya

    ReplyDelete
  12. Hi this is dwarakesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know
    indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
    java training in chennai website where someone please help me to identity the syllabus covers everything or not??

    thanks, dwarakesh

    ReplyDelete
  13. Hi this is dwarakesh i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know
    indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
    java training in Chennai website where someone please help me to identity the syllabus covers everything or not??

    thanks, dwarakesh

    ReplyDelete
  14. Hi this is babu i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in

    php but dont know
    indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
    java training in chennai website where someone please help me to identity

    the syllabus covers everything or not??

    thanks, babu

    ReplyDelete
  15. Hi this is babu i am having 3 years of experience as a php developer and i am certified. i have knowledge on OOPS concepts in php but dont know
    indepth. After learning java will be enough to get a good career in IT with good package? and i crossed
    java training in Chennai website where someone please help me to identity the syllabus covers everything or not??

    thanks, babu

    ReplyDelete
  16. Excellent post!!! The future of cloud computing is on positive side. With most of the companies integrate Salesforce CRM to power their business; there is massive demand for Salesforce developers and administrators across the world. Salesforce Training Institutes in Chennai

    ReplyDelete
  17. Your blog is really awesome. Thanks for sharing this blog. Suppose if anyone want to get PHP Training Chennai, please visit Fita academy located at Chennai, Velachery.

    ReplyDelete
  18. Hi I am Emi lives in Chennai. I am a technology freak. Recently I did Java Training in Chennai at a leading Java Institutes in Chennai. This is really helpful for me to make a bright carrer in IT industry.

    ReplyDelete
  19. Informatica training in chennai
    Thanks for sharing these niche piece of coding to our knowledge. Here, I had a solution for my inconclusive problems & it’s really helps me a lot keep updates…
    Informatica training center in Chennai

    ReplyDelete
  20. Salesforce Training

    The information you posted here is useful to make my career better keep updates..I did Salesforce Training in Chennai at FITA academy. Its really useful for me to make bright future in IT industry.

    Salesforce CRM Training in Chennai

    Salesforce Admin Training in Chennai

    Salesforce.com Training in Chennai

    Sales Cloud Consultant Training in Chennai

    ReplyDelete
  21. QTP Training in Chennai

    Hi, I wish to be a regular contributor of your blog. I have read your blog. Your information is really useful for beginner. I did Selenium Training in Chennai at Fita training and placement academy which offer best Software Testing Course in Chennai with years of experienced professionals. This is really useful for me to make a bright career.

    ReplyDelete
  22. HTML5 Training

    Hi, Thanks for sharing this valuable blog.I was really impressed by reading this blog. I did HTML5 Courses in Chennai at reputed HTML5 Training Institutes in Chennai. This is really useful for me to make a bright future in designing field.

    Best HTML5 Training in Chennai

    ReplyDelete
  23. PHP Training Chennai

    I get a lot of great information from this blog. Thank you for your sharing this informative blog. Recently I did PHP course at a leading academy. If you are looking for best PHP Training Institute in Chennai visit FITA IT training academy which offer real timePHP Training in Chennai.

    PHP Course in Chennai

    ReplyDelete
  24. Java Training Chennai

    Hi I am Mathews lives in Chennai. I am a technology freak. Recently I did Java Course in Chennai at a leading Java Training Institutes in Chennai. This is really helpful for me to make a bright career in IT industry.

    Java Training in Chennai | Java Training in Velachery

    ReplyDelete
  25. I gathered a lot of information through this article.Every example is easy to understandable and explaining the logic easily.Thanks! Android Training in chennai | Android Training chennai | Android course in chennai | Android course chennai

    ReplyDelete