Hiding Master View Controller in SplitView regardless of device orientation - objective-c

I've found lots of people asking for information on how to have the Master view displayed both in landscape and portrait orientation, but what I am trying to do is to having the right master view hidden regardless of the devices orientation and popping in from the side by using a navbar button.
What would help me enormously would be if someone could tell me where the logic for hiding the master view is located/executed when the device reorients. I've been looking at the template that comes with Xcode, Master/detail view for iOS, and I noticed these two following methods are declared in the AppDelegate.m file but I can't seem to find out where they are being executed from:
//Called when a button should be added to the nav bar for a view that is hidden
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController: (UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(#"Master", #"Master");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
All help would be appreciated.

You actually have no control over a UISplitViewController. The master view is always present in landscape view, and there is no possible way of changing this.
However, "Matt Gemmell created an excellent custom splitViewController called 'MGSplitViewController'. It is very easily implemented, heavily commented, and contains a lot of excellent features not found with a normal splitViewController (hide master view on landscape view, change placement of the split in landscape view, allow user to change size of split fluidly during runtime, etc)."
Info and demo: http://mattgemmell.com/2010/08/03/mgsplitviewcontroller-updated/
Straight to the source: https://github.com/mattgemmell/MGSplitViewController/
-=-=-=-=-=-=-=-=-=-=-=-
I've posted this before in a similar (but different) question with the same answer here:
How to hide master view in UiSplitviewcontroller in ipad
-=-=-=-=-=-=-=-=-=-=-=-
UPDATE:
In iOS 5.0 and beyond, they have finally added functionality to hide master view in landscape!
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}
Reference:
splitViewController in Ipad that doesnt hide in portrait

Related

Shows a faded gray color view through iOS 7 Navigation bar of a UISplitViewController

I have written a test iPad app which contains only a split view.
I used the storyboard for set the split view. I did not do any modification to the generated split view controller by the storyboard. But did some modifications to the master view controller and the detail view controller as follow,
Master View Controller:
- (void)viewDidLoad
{
[super viewDidLoad];
............
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
Detail View Controller:
- (void)viewDidLoad
{
.....................
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
[self.navigationController.navigationBar setBackgroundColor:[UIColor whiteColor]];
}
When launch the app, I noticed that the edges of the faded view appear on the navigation bar. This issue is not exist when I do not set edgesForExtendedLayout for the view controllers.
But it is needed to add.
Any Idea. Please help.
This is an example which has provided by the Apple documentation. This issue is exist with it too. https://developer.apple.com/LIBRARY/IOS/samplecode/Popovers/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010436
I'm not sure, because I'm still learning iOS development but I'm searching for a way to removing the the default left, annoying, offset in a TableView when displaying cells. After googling, I found this answer https://stackoverflow.com/a/18986158/3022883 and if you unselect "Under Bottom Bars" the TabBar (bottom) stays grey. Each cell in a UITableViewController is reused every time you scroll, so since the space in the TabBar is not used to display a cell, I'm assuming that it's the background colour of the TableView.

Hide MasterViewController when clicking a button

I have a Master/Detail application and everything works right..i added a button with the purpose of taking me to another tableViewController. I need, when i go to that table view controller, to hide permanently the master view controller from portrait and landscape mode.So to recapitulate, i am in a newly created table view controller independent from the original Detail View Controller, and i need to hide permanently the master view controller when this button is clicked and the new TableViewController is loaded..How can i do it ? I tried to use a MGSplitViewController but i got lost using it..i'm a newb in Xcode development. Any help will be highly appreciated.Update 1:My problem is not with the Detail View Controller...in the Detail ViewCOntroller i have added a button that will take me to another tableviewcontroller...now when i load that i need to force the masterviewcontroller to stay hidden how can i do it?
Once you configure your detail view controller, you need to need to dismiss the popover controller.
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
}
If your detail view controller doesn't already have a property to hold the UIPopoverController, you can capture it by implementing these delegate methods for UISplitViewControllerDelegate
- (void)splitViewController:(UISplitViewController *)iSplitViewController
willHideViewController:(UIViewController *)iViewController
withBarButtonItem:(UIBarButtonItem *)iBarButtonItem
forPopoverController:(UIPopoverController *)iPopoverController {
self.popoverController = iPopoverController;
}
- (void)splitViewController:(UISplitViewController *)iSplitViewController
willShowViewController:(UIViewController *)iViewController
invalidatingBarButtonItem:(UIBarButtonItem *)iBarButtonItem {
self.popoverController = nil;
}

Disable auto hide Popover in SplitViewController in portrait mode

In my app I am using a SplitViewContorller. In portrait mode I don't want the popover disappear when the user touch outside of it. I want keep in front till the user do something. How it's possible to do that?
In your UISplitViewControllerDelegate, implement splitViewController:popoverController:willPresentViewController:. In that method, you should be able to set yourself as the delegate to the UIPopoverController that is about to be displayed. Then, you can simply return NO from popoverControllerShouldDismissPopover:. You will then be responsible for dismissing the UIPopoverController programatically.
OK, here the code that explain the Sebastian answer, just wrote it on DetailViewController.m:
- (void)splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController {
pc.delegate = self; }
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
return NO; }

willHideViewController not called when switching to view in portrait mode

My iPad app uses the standard UISplitViewController. My problem is, if I
Rotate to portrait, I put a Popover button for the Master list - Fine
Select an item via the popover, that changes the detailview (This uses a prepareForSegue which sets self.splitViewController.delegate = newViewDetailViewController;
The resulting detailview is now missing a popoverbutton. If I rotate to landscape, the master list appears. If I then again rotate to portrait, a popoverbutton appears.
So - How can I ensure willHideViewController will be called on viewDidLoad, for example?
I can detect what the orientation is, but I still need the barbuttonitem and popovercontroller needed in
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
For now I am following Apples MultipleDetailView example as suggested here.
But since I am having multiple MasterControllers as well, it's a real hassle to store (a static) pointer to the popoverbutton item and setting it every time I push a level on my masterview controller.
Hopefully, someone has a good way of solving this problem :-)
I ran into the same problem and finally figured out what was missing. There is a little code in the AppDelegate to performs some initialization. It is in the didFinishLaunchingWithOptions method. Here is the code that goes in there:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
They're all important to operate the split view controller, but the last line is the most line for getting the method to fire is the last one. I am building a universal application and this was missing. To ensure that it didn't affect my iPhone side I wrapped it in a UI_USER_INTERFACE_IDIOM check.

UiImagePickerController - Additional Preview Screen With Overlay

The latest "Yelp" app provides "Add Business Photo" functionality. After taking a photo the preview screen is displayed as usual. However tapping the "use" button displays what appears to be the same preview screen with an overlay containing buttons and a textfield to enter a caption. I've read that the way to display an overlay on the preview screen "ONLY" is as follows:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
I've yet to get this to work :) however I'm now debating on what approach to use in order to display the preview screen twice ie. once normally and then afterward with overlay?
I dont know the ins and outs of UIImagePickerController yet and and I'm wondering if its possible to insert the overlay above the preview and re-display the preview after the preview has been displayed (not sure if thats possible) or create and display a entirely new view (copy of preview with overlay applied)? (not sure how I would do that either).
Thanks in advance for your input..
The UIImagePickerController is a navigation controller. That means you can push things on and off of the view controller stack controlled by the image picker. When you get the imagePickerController:didFinishPickingMediaWithInfo: notification, just push another view onto the image picker stack like this.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *imageURL = [info objectForKey:UIImagePickerControllerMediaURL];
MyCustomPreviewController *customPreview = [[MyCustomPreviewController alloc] initWithImageURL:imageURL];
[picker pushViewController:customPreview animated:YES];
}