Eventually:
Master Controller Beyondviewcontroller
Inherit from Uisplitviewcontroller
beyondviewcontroller.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c ) 2014 Com.beyond. All rights reserved.// Master controller, inherit from Uisplitviewcontroller, left Master controller is: Foodtypelistctrl, right slave controller is foodlistctrl# Import <UIKit/UIKit.h> @interface Beyondviewcontroller:uisplitviewcontroller@end
beyondviewcontroller.m//27_splitviewctroller////Created by Beyond on 14-8-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//Master Controller, inherit from Uisplitviewcontroller, the left master controller is: Foodtypelistctrl, the right slave controller is Foodlistctrl#import " BeyondViewController.h "//Menu Series Table Controller #import" FoodTypeListController.h "//Menu List Controller #import" FoodListController.h "//Cuisine List The protocol defined by the Controller, the purpose of which is to tell the agent (that is, the menu list controller) which one of the dishes under the menu is clicked #import "FoodTypeListCtrlDelegate.h" @interface Beyondviewcontroller () <FoodTypeListCtrlDelegate> @end @implementation beyondviewcontroller//Important ~ ~ ~ The main controller acts as a middleman, First get Foodtypelistcontroller, and become its agent, get a row of the menu table is clicked when the corresponding Cuisine object//And then in the Foodtypelistcontroller agent method, Get Foodlistcontroller, and further transfer the cuisine to foodlistcontroller-(void) viewdidload{[Super Viewdidload]; 1. First get the master controller, namely the navigation controller, then get Foodtypelistcontroller from the navigation controller, and become its agent uinavigationcontroller *foodtypelistnav = [ Self.childviewcontrollers Firstobject]; Foodtypelistcontroller *foodtypelistctrl = [Foodtypelistnav.childviewcontroLlers Firstobject]; Foodtypelistctrl.delegate = self; Let Foodlistctrl become the agent of the master controller, just listen to the appearance and hiding of the master controller, and display the corresponding prompt text on the left button of Foodlistctrl (click the text to expand the hidden master controller) Uinavigationcontroller *foodlistnav = [Self.childviewcontrollers lastobject]; foodlistcontroller<uisplitviewcontrollerdelegate> *foodlistctrl = [foodlistnav.childviewcontrollers Firstobject]; Self.delegate = Foodlistctrl;} 2. And then in the proxy method of Foodtypelistcontroller, get Foodlistcontroller, and further pass the cuisine to foodlistcontroller-(void) Foodtypelistcontroller: (Foodtypelistcontroller *) foodtypesvc didselectedfoodtype: (FoodType *) type{ Uinavigationcontroller *foodlistnavi = [Self.childviewcontrollers lastobject]; Foodlistcontroller *foodlistctrl = [Foodlistnavi.childviewcontrollers firstobject]; Foodlistctrl.foodtype = type; [Foodlistnavi Poptorootviewcontrolleranimated:yes];} @end
Splitviewctrl Master Master Controller ,
Inherit from table controller
Foodtypelistcontroller "Vegetable Series table" and its agent
foodtypelistcontroller.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c) Com.beyond 2014. All rights reserved.// Splitviewctrl Master Master Controller, inherited from table Controller "menu series table" #import <UIKit/UIKit.h> @protocol Foodtypelistctrldelegate; @interface foodtypelistcontroller:uitableviewcontroller//member: Agent, when clicked on a line, tell the agent that you clicked on which kind of cuisine, Thus, the controller on the right shows the corresponding list of dishes @property (weak, nonatomic) id<foodtypelistctrldelegate> delegate; @end
foodtypelistcontroller.m//27_splitviewctroller////Created by Beyond on 14-8-31.//Copyright (c) 2014 Com.beyon D. All rights reserved.//#import "FoodTypeListController.h" #import "FoodType.h" #import "FoodTypeListCtrlDelegate.h" @ Interface Foodtypelistcontroller ()//Member: An array that holds all the Foodtype@property (strong, nonatomic) from dictionary one by one to objects loaded from the plist Nsarray * Foodtypesarr; @end @implementation foodtypelistcontroller//getter access is loaded, lazy loading-(Nsarray *) foodtypesarr{if (_ Foodtypesarr = = nil) {//Classic, a sentence converts the dictionary array in the plist file corresponding to the parameter into an array of objects of that class _foodtypesarr = [FoodType Objarrfromplistnam e:@ "Food_types.plist"]; } return _foodtypesarr;} -(void) viewdidload{[Super Viewdidload]; Self.title = @ "Cuisine"; By default, select line No. 0, call your own method, and pass the data model to it [Self.tableview Selectrowatindexpath:kindexpathzero animated:yes scrollposition: Uitableviewscrollpositiontop]; Let line No. 0, show the selected state, need to overwrite the system default method: Viewwillappear [self TableView:self.tableView Didselectrowatindexpath:kindexpathzero] ;} Cancel some of the system default events, let line No. 0,Show checked state-(void) Viewwillappear: (BOOL) animated{//Do nothing ...} #pragma mark-Data source method//How many lines-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{re Turn Self.foodTypesArr.count;} cell-(UITableViewCell *) shown per line TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ static NSString *id = @ "FoodType"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:id]; if (cell = = nil) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:id]; }//model array to remove the corresponding row model FoodType *type = Self.foodtypesarr[indexpath.row]; Set unique content cell.textLabel.text = Type.Name; returns cell return cell; #pragma mark-Proxy Method-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//If generation (The right-hand slave controller) is required to tell which cuisine is currently selected if ([Self.delegate respondstoselector: @selector (foodtypelistcontroller: Didselectedfoodtype:)]) {FoodType *type = Self.foodtypesarr[indexpath.row]; [Self.delegate foodtypelistcontroller:self Didselectedfoodtype:type]; }} @end
well-defined protocols
foodtypelistctrldelegate.h// 27_splitviewctroller//// Created by beyond on 14-8-31.// Copyright (c) 2014 Com.beyond. All rights reserved.//#import <Foundation/Foundation.h> @class foodtype @protocol foodtypelistctrldelegate < Nsobject> @optional//When a row is clicked, tell the agent what kind of cuisine was clicked, so that the controller on the right shows the corresponding menu name-(void) Foodtypelistcontroller: ( Foodtypelistcontroller *) Ctrl Didselectedfoodtype: (FoodType *) FoodType; @end
Foodlistcontroller
Splitviewctrl from controller , inherit from table controller
Show A list of all the dishes under a certain cuisine.
foodlistcontroller.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c ) 2014 Com.beyond. All rights reserved.// Splitviewctrl from the controller, inherits from the table controller a certain cuisine under the "List of dishes"// click on a row in the Left Menu series table Controller, This controller will show all dishes under this cuisine #import <UIKit/UIKit.h> @class foodtype; @interface foodlistcontroller:uitableviewcontroller// The data source, according to the imported cuisine, through its idstr, pieced together a new plist name, loaded, turned into food model object array @property (strong, nonatomic) FoodType *foodtype; @end
foodlistcontroller.m//27_splitviewctroller////Created by Beyond on 14-8-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "FoodListController.h" #import "FoodDetailController.h" #import "Food.h" #import " FoodCell.h "#import" FoodType.h "//Become a proxy for uisplitviewcontrollerdelegate to listen to its display and hide methods, Thus controlling the display and hiding of Leftbarbuttonitem @interface Foodlistcontroller () <UISplitViewControllerDelegate> @property (Strong , nonatomic) Nsarray *foodsarr, @end @implementation foodlistcontroller-(void) viewdidload{[Super Viewdidload]; }//Important ~ ~ ~ Intercept the Setterfoodtype method, set the caption, load the data from the corresponding plist, and turn it into an array of objects, refresh the table-(void) Setfoodtype: (FoodType *) foodtype{_foodtype = FoodType; NSString *filename = [NSString stringwithformat:@ "Type_%@_foods.plist", foodtype.idstr]; The classic, a word of the argument corresponds to the dictionary array in the plist file, to the object array of that class Self.foodsarr = [Food objarrfromplistname:filename]; Self.title = Foodtype.name; if (self.isviewloaded) {//default let TableView scroll to line No. 0 [Self.tableview ScrolltorowatindexpatH:kindexpathzero Atscrollposition:uitableviewscrollpositiontop Animated:yes]; Refresh table [Self.tableview Reloaddata]; }} #pragma Mark-splitviewctrl proxy method//will show Master host controller-(void) Splitviewcontroller: (Uisplitviewcontroller *) Svc Willshowviewcontroller: (Uiviewcontroller *) Aviewcontroller Invalidatingbarbuttonitem: (UIBarButtonItem *) barbuttonitem{Self.navigationItem.leftBarButtonItem = nil;} The Master master controller is about to be hidden-(void) Splitviewcontroller: (Uisplitviewcontroller *) svc Willhideviewcontroller: (Uiviewcontroller *) Aviewcontroller Withbarbuttonitem: (Uibarbuttonitem *) Barbuttonitem Forpopovercontroller: (UIPopoverController *) pc{Barbuttonitem.title = @ "Cuisine"; Self.navigationItem.leftBarButtonItem = Barbuttonitem;} #pragma mark-Data source method//How many lines-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{re Turn Self.foodsArr.count;} The Foodcell is highly encapsulated and the controller knows very little-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) INDexpath{Foodcell *cell = [Foodcell Cellwithtableview:tableview]; Cell.food = Self.foodsarr[indexpath.row]; return cell;} #pragma mark-Proxy method//cell row high-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return 100;} Select a row-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//click on the corresponding model Food *food = Self.foodsarr[indexpath.row]; Fooddetailcontroller *DETAILVC = [[Fooddetailcontroller alloc] init]; Pass the data model, inside will intercept detailvc.food = food; [Self.navigationcontroller PUSHVIEWCONTROLLER:DETAILVC animated:yes];} @end
WebView Show details of a dish
fooddetailcontroller.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c ) 2014 Com.beyond. All Rights reserved.// Click on a line in the menu control, come here, show the details of the dish, directly with WebView show #import <UIKit/UIKit.h> @class food;@ Interface fooddetailcontroller:uiviewcontroller//data source, to show which Dish @property (strong, nonatomic) food *food; @end
fooddetailcontroller.m//27_splitviewctroller////Created by Beyond on 14-8-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//Click on one line, come here, show the details of the dish, directly with WebView show #import "FoodDetailController.h" #import "Food.h" @interface Fooddetailcontroller () @property (weak, nonatomic) UIWebView *webview; @end @implementation fooddetailcontroller// Let Weibview be the controller's view-(void) loadview{UIWebView *webview = [[UIWebView alloc] init]; Bounds is the entire screen area, Applicationframe is the app display area, does not include the status bar Webview.frame = [UIScreen mainscreen].applicationframe; With the screen rotated, the wide-height auto-Scaling webview.autoresizingmask = Uiviewautoresizingflexiblewidth | Uiviewautoresizingflexibleheight; Self.view = WebView; Member variables, remember that the purpose is to avoid strong turn self.webview = WebView;} -(void) viewdidload{[Super Viewdidload]; Navigation bar Title Self.title = Self.food.name; Key points ~ ~ ~ Stitching Local URL, note: If you create a real folder in the sandbox, then load the file, add the folder name NSString *filename = [NSString stringwithformat:@ "html/food/%@.html ", Self.food.idstr]; Nsurlrequest *request = [nsurlrequest requestwithurl:[[nsbundle mainbundle] urlforresource:filename Withextension:nil]]; [Self.webview loadrequest:request];} @end
Model
food.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c) 2014 Com.beyond . All rights reserved.// model: A dish food corresponds to a dictionary inside the plist file #import <Foundation/Foundation.h> @interface Food: nsobject//must be identical to the dictionary key in the plist file//id@property (copy, nonatomic) nsstring *idstr;//dish name @property (copy, nonatomic) Nsstri Ng *name;//Small icon url@property (copy, nonatomic) nsstring *imageurl;//Web page url@property (copy, nonatomic) NSString *url;//This course Estimated time-consuming @property (copy, nonatomic) NSString *time;//making much more difficult @property (copy, nonatomic) NSString *diff; @end
foodtype.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c) 2014 Com.beyond. All rights reserved.// model: A Dictionary of cuisines foodtype corresponding plist files #import <foundation/foundation.h>@ Interface foodtype:nsobject//id@property (copy, nonatomic) nsstring *idstr;//cuisine Name: Cantonese Style Szechuan Cuisine @property (copy, Nonatomi c) NSString *name; @end
A cell View of the package
foodcell.h// 27_splitviewctroller//// Created by Beyond on 14-8-31.// Copyright (c) 2014 Com.beyond. All rights reserved.// custom cell, a cell shows the data inside a food model, the purpose of the incoming TableView instantiation cell is to encapsulate the most thorough, let the controller do the least thing, know least #import <UIKit/UIKit.h> @class food; @interface foodcell:uitableviewcell//Data source model that provides data to the inner child controls to display, Internal will intercept setter method @property (strong, nonatomic) food *food;//incoming TableView instantiate the cell with the purpose of encapsulating the most thorough, let the controller do the least thing, know the least + (instancetype ) Cellwithtableview: (UITableView *) TableView; @end
foodcell.m//27_splitviewctroller////Created by Beyond on 14-8-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "FoodCell.h" #import "Food.h" #import "uiimageview+webcache.h" @interface Foodcell () @ Property (weak, nonatomic) Iboutlet Uiimageview *iconview; @property (weak, nonatomic) Iboutlet UILabel *namelabel;@ Property (weak, nonatomic) Iboutlet UILabel *desclabel; @end @implementation foodcell//incoming TableView instantiates the cell for the most thorough encapsulation, Let the controller do the least thing, know the least + (Instancetype) Cellwithtableview: (UITableView *) tableview{//Cellid must be exactly the same as in Xib NSString *ce Llid = @ "Foodcell"; Foodcell *cell = [TableView dequeuereusablecellwithidentifier:cellid]; if (cell = = nil) {//create cell from xib = [[[NSBundle Mainbundle] loadnibnamed:cellid owner:nil Options:nil] Lasto Bject]; On the right is the arrow Cell.accessorytype = Uitableviewcellaccessorydisclosureindicator; } return cell; The data source model that provides the data to the internal child controls shows that the internal interceptor setter Method-(void) Setfood: (Food *) food{_food = food; Small icon [Self.iconview setimagewithurl:[nsurl URLWITHSTRING:FOOD.IMAGEURL] Placeholderimage:[uiimage imagenamed:@ "Tim Eline_image_placeholder "]; Dish name self.nameLabel.text = food.name; Subtitle Self.descLabel.text = [NSString stringwithformat:@ "Difficulty:%@ Duration:%@", Food.diff, Food.time]; } @end
XIB
Simple use of Ios_27splitviewcontroller