IOS programming Uisplitviewcontroller?
The IPad, on the other hand, have plenty of screen space to present both views using a built-in class called Uisplitviewcon Troller.
The IPad has enough screen space to show two view built-in classes called Uisplitviewcontroller.
Uisplitviewcontroller is an ipad-only class that presents the view controllers in a master-detail relationship.
Uisplitviewcontroller is a ipad-only class that shows two view controllers in the Master-detail relationship.
The master view controller occupies a small strip on the lefthand side of the screen, and the detail view Controller Occup IES the rest of the screen.
The master view controller occupies a small screen on the left, and the detail view controller occupies the remaining screen.
You'll also make Nerdfeed a universal application and has it continue to use a uinavigationcontroller when run on the I Phone.
1. Splitting up Nerdfeed
Creating a uisplitviewcontroller is simple since you has already learned about navigation controllers and Tab bar control Lers.
When you initialize a split view controller, you pass the it an array of view controllers just like with a tab bar controller.
When you initialize? A split view controller, you send him a list of view controllers like a tab bar controller.
In Application:didfinishlaunchingwithoptions:, check whether the device was an iPad before instantiating a uisplitviewcontr Oller. The Uisplitviewcontroller class does not exist on the iPhone, and trying to create an instance of Uisplitviewcontroller WI ll cause an exception to be thrown.
In Application:didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions Check if the device is an ipad app before instantiating Uisplitviewcontroller.
Check to make sure we is running on the IPad
if ([uidevice currentdevice].userinterfaceidiom = = Uiuserinterfaceidiompad) {
Webviewcontroller must is in navigation controller; You'll see why
Later
Uinavigationcontroller *detailnav =
[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:WVC];
Uisplitviewcontroller *svc = [[Uisplitviewcontroller alloc] init];
Set the delegate of the split view controller to the detail VC
You'll need this later-ignore the warning for now
Svc.delegate = WVC;
Svc.viewcontrollers = @[masternav, Detailnav];
Set the root view controller of the window to the Split view controller
Self.window.rootViewController = svc; }
else {
On Non-ipad devices, just use the navigation controller
Self.window.rootViewController = Masternav;
}
A Split View Controller must has both the master and the detail view controller when it is created.
A split view controller must have the master and detail view Controller when it is created.
Uisplitviewcontroller works:in landscape mode, there master view controller is shown in a small strip on th E left hand side of the screens and the detail view controller takes over the rest of the screens.
Uisplitviewcontroller in landscape mode, master view? The controller shows up in a small area on the left, where the detail view controller occupies the rest of the screen.
To address this problem, when a row was tapped, you need to check whether the Bnrcoursesviewcontroller is a member of a SPL It view controller and, if it is, take a different action.
To locate this problem, when a row is selected, you need to check if Bnrcoursesviewcontroller is a member of the Split view controller, and if so, take a different action.
You can send the message splitviewcontroller to any uiviewcontroller, and if that view controller was part of a split view Controller it would return a pointer to the split view controller
You can send a message to Splitviewcontroller to any uiviewcontroller, and if the view controller is part of the Split view controller, it will return a pointer to the split view Controller.
Otherwise, it returns nil.
Otherwise, nil will be returned.
View controllers is SMART:A View controller would return this pointer if it is a member of the Split view controller ' s AR Ray or if it belongs to another controller, which is a member of a split view controller's array (as is the case with both B Nrcoursesviewcontroller and
Bnrwebviewcontroller).
View controllers is smart: The View controller will return this pointer, if he is a member of the Split view controller or it belongs to another controller, it is the members of the Split view controller.
In bnrcoursesviewcontroller.m, locate the method Tableview:didselectrowatindexpath:. At the top of this method, check for a split view controller before pushing the Bnrwebviewcontroller onto the navigation s Tack.
At the beginning of this method, before pushing the bnrwebviewcontroller to the navigation stack, check the Split view controller first.
?
if (!self.splitviewcontroller) {
[Self.navigationcontroller PushViewController:self.webViewController
Animated:yes];
}
Now, if the Bnrcoursesviewcontroller isn't in a split view controller, you assume the device isn't an iPad and bnrcourse Sviewcontroller pushes the bnrwebviewcontroller onto the navigation controller ' s stack.?
If Bnrcoursesviewcontroller is in a split-view controller, then it's left-to-the-uisplitviewcontroller to place the Bnrwe Bviewcontroller on the screen.
2 Displaying the Master View Controller in Portrait Mode
Display master view Controller under portrait mode?
Uisplitviewcontroller lets you do just so by supplying it delegate with a uibarbuttonitem.
Uisplitviewcontroller lets you do this by providing its delegate with Uibarbuttonitem.
Tapping this button shows the master view controller in a specialized Uipopovercontroller
Clicking on this button will show the Master view controller in the specialized Uipopovercontroller.
In your code, whenever a detail view controller is given to the split view controller, that detail
View Controller was set as the Split view controller ' s delegate.
In your code, when a detail
The view controller is given a split view controller, detail view? The controller is set to the delegate of the Split view controller.
As the delegate, the detail view controller would get a pointer to the Uibarbuttonitem when rotating to portrait mode.
As a Delegate,detail view controller there will be a pointer to Uibarbuttonitem when in portrait mode.
In BNRWebViewController.h, add this declaration:
?
@interface Bnrwebviewcontroller:uiviewcontroller
<UISplitViewControllerDelegate>
In BNRWEBVIEWCONTROLLER.M, implement the following delegate method to place the Bar button item in the Bnrwebviewcontroll Er ' s navigation item.
In the BNRWEBVIEWCONTROLLER.M method, implement the following delegate method to place the bar button item into the Bnrwebviewcontroller navigation item.
?
-(void) Splitviewcontroller: (Uisplitviewcontroller *) svc Willhideviewcontroller: (Uiviewcontroller *) Aviewcontroller
Withbarbuttonitem: (Uibarbuttonitem *) Barbuttonitem Forpopovercontroller: (Uipopovercontroller *) PC
{
If This bar button item does not has a title, it would not be appear at all
Barbuttonitem.title = @ "Courses";
Take this bar button item and put it on the side of the NAV item
Self.navigationItem.leftBarButtonItem = Barbuttonitem;
}
Notice that you explicitly set the title of the button. If The button does not has a title, it won't appear at all.
Notice that you explicitly set the caption of the button. If the button does not have a title, you will not be displayed at all.
If The master view controller ' s Navigationitem has a title and then the button would be automatically set to that title.
If the master view controller's Navigationitem has a title, the button is automatically set to that title.
Rotate to portrait mode, and you'll see the bar button item appear on the left of the navigation bar. Tap that button, and the Master view controller ' s view would appear in a uipopovercontroller.
On the left side of navigation bar, you will see Bar button item. Clicking on this button,master View controller's view will be displayed in Uipopovercontroller.
This bar button, item is had, we always put the detail view controller inside a navigation controller.
This bar button item is the reason why we always put detail view controller inside a navigation controller.
Navigation Controller to put a view controller in a split view controller, but it makes using the Bar button item much easier.
You do not need to use the navigation controller to place a view controller in the Split view controller, but that will make it easier to use Bar button item.
There is-small issues left-to-address with your Courses button. First, when the device was rotated back to landscape mode, the button is still there.
Now there are two small problems, first of all, when your device is rotated to landscape mode, the button is still there.
To remove it, the delegate needs to respond to another message from the Uisplitviewcontroller.
In order to remove these, delegate needs to respond to another message from Uisplitviewcontroller.
Implement this delegate method in BNRWEBVIEWCONTROLLER.M.
-(void) Splitviewcontroller: (Uisplitviewcontroller *) svc Willshowviewcontroller: (Uiviewcontroller *) Aviewcontroller
Invalidatingbarbuttonitem: (Uibarbuttonitem *) Barbuttonitem
{
Remove the bar button item from the Navigation item
Double Check that it's the correct button, even though we know it is if (Barbuttonitem = = Self.navigationItem.leftBarB Uttonitem) {
Self.navigationItem.leftBarButtonItem = nil; }
}
The Courses button would now appear and disappear as you rotate between portrait and landscape modes.
3? Universalizing nerdfeed General-purpose Nerdfeed
(1) As you built Nerdfeed, you were careful on the device differences in the classes used.
(2) Nerdfeed is still a relatively simple application. It's always easier to universalize a application early in development. As an application grows, it details get buried in the massive pile of code. Finding and fixing issues as you are writing code was much easier than coming back later. Details were harder to find, and there was the risk of breaking what already works.
?
?
?
?
?
?
IOS Programming Uisplitviewcontroller