Adding Button to Show Master View from Detail View - ios

I am trying to add a button to my navigation bar on my detail view to show the master view when in portrait mode but the button isn't showing up. Can anyone help or offer suggestions?
Here is how I was trying to do it in the detail view:
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
mainMenu = barButtonItem;
[mainMenu setTitle:#"Menu"];
[[self navigationItem]setLeftBarButtonItem:mainMenu];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
if (mainMenu == [[self navigationItem]leftBarButtonItem])
{
[[self navigationItem]setLeftBarButtonItem:nil];
}
}
Here is how I'm loading the detail view when selecting a row in my master view:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:webViewController];
[details replaceObjectAtIndex:1 withObject:detailNav];
self.splitViewController.viewControllers = details;
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.window.rootViewController = self.splitViewController;
I've added this to viewDidLoad and the button shows up now but I'm not sure how to get it to show the master view.
mainMenu = [[UIBarButtonItem alloc]init];
[mainMenu setTitle:#"Menu"];
self.navigationItem.leftBarButtonItem = mainMenu;
Here is a picture of what it looks like when I swipe from the left to show the master view.
I've managed to get a left button to appear but now I don't know how to have it open the master view. Here is how I got the button to show up:
mainMenu = [[UIBarButtonItem alloc]init];
[mainMenu setTitle:#"Menu"];
self.navigationItem.leftBarButtonItem = mainMenu;

Rather than left button, use right bar button and it will show. The problem is the button on the left gets hidden by the default button of the vavigation controller. Try the right bar button.
Edit
This is a generic method that is placed in view did load to include a right bar button. then you can access is in other methods. hope it helps.
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
In here insert new object in the selector is the IBAction that you use to declare what that button has to do.

Related

add a back button to UIImagepicker controller navigation nar

i have a UI Image picker and its being shown inside a UI popoverController, i need a back button on UIimage picker navbar, so i can go back to previous popover.
let me explain in details.
1) i have a popup in which i tap and raise a notification, this notification is read on a view controller where i want this camera image picker popup. following is my code
-(void)registerNotificationForCameraSource
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(mediaSourceCallback:) name:NOTIFICATION_FOR_CAMERA_SOURCE object:nil];
}
#pragma mark - Image picker Popover
-(void)mediaSourceCallback:(NSNotification *)notificationObj
{
capturedImages = [[NSMutableArray alloc] init];
pickerObj = [[UIImagePickerController alloc] init];
// [pickerObj setContentSizeForViewInPopover:CGSizeMake(320,480)];
pickerObj.delegate = self;
if ([notificationObj.object isEqualToString:#"UIImagePickerControllerSourceTypeCamera"])
{
pickerObj.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerObj.modalPresentationStyle = UIModalPresentationFullScreen;
pickerObj.showsCameraControls = YES;
[self presentViewController:pickerObj animated:YES completion:nil];
}
else
{
[[UINavigationBar appearanceWhenContainedIn:[ApplicationDiscriptionPopupViewController class], nil] setBarTintColor:[UIColor redColor]];
pickerObj.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleDone target:self action:#selector(imagePickerBackButtonTapped)];
[pickerObj.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[pickerObj setNavigationBarHidden:NO animated:YES];
//navigationControllerObj = [[UINavigationController alloc] initWithRootViewController:applicationDiscriptionPopupViewControllerObj];
_popoverControllerObj.popoverContentSize = CGSizeMake(320,480);
pickerObj.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[pickerObj presentedViewController];
[_popoverControllerObj setContentViewController:pickerObj animated:YES];
}
}
-(void)imagePickerBackButtonTapped
{
[pickerObj popToViewController:applicationDiscriptionPopupViewControllerObj animated:YES]; }
pickerObj is UI Image picker
applicationDiscriptionPopupViewControllerObj is view controller of my previous popover view. from where i came. now i wana go back to this view in the popup, when i tap on back button in nav bar.
but i dnt hav any nav bar. plz help
If you are adding a UIImagePickerController via presentViewController inside a UIViewController then you should see the default navigation bar. You should implement :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *navBarTopItem;
// you cannot add a custom back button with native back button look like, so use image over
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"back_arrow.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(backAction)];
navBarTopItem.title = #"Albums"; // "Camera
navBarTopItem.leftBarButtonItem = backButton;
}
Add a back button action handler
-(void)backAction{
[self.navigationController popViewControllerAnimated:YES];
}
Hope that answer ur Q.

UISplitViewController consistent divider

In my iPad App I'm using a UISplitViewController with two UINavigationControllers as master and detail. In Potrait I'd like the master to be hidden and accessible via UIPopoverViewController. This is the implementation of my UISplitViewController subclass, which works fine:
- (id)init {
self = [super init];
if (self) {
_splitViewController = [[UISplitViewController alloc] init];
_splitViewController.delegate = self;
_searchViewController = [[UIViewController alloc] init];
_searchViewController.view.backgroundColor = [UIColor whiteColor];
_masterNavController = [[UINavigationController alloc] initWithRootViewController:_searchViewController];
_masterNavController.navigationBar.translucent = NO;
_mapViewController = [[MapViewController_iPad alloc] init];
_detailNavController = [[UINavigationController alloc] initWithRootViewController:_mapViewController];
_detailNavController.navigationBar.translucent = NO;
_splitViewController.viewControllers = #[_masterNavController, _detailNavController];
_splitViewController.view.backgroundColor = [UIColor redColor];
}
return self;
}
#pragma mark -
#pragma mark - UISplitViewControllerDelegate
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
svc.view.backgroundColor = [UIColor redColor];
barButtonItem.title = NSLocalizedString(#"ipad_search_vc_bar_button_title", #"Name of the master view controller button on iPad");
[self.mapViewController.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
svc.view.backgroundColor = [UIColor redColor];
[self.mapViewController.navigationItem setLeftBarButtonItem:nil animated:YES];
}
- (void)splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController {
svc.view.backgroundColor = [UIColor redColor];
[pc setPopoverBackgroundViewClass:[CustomPopoverBackgroundView class]];
}
This is how it looks:
After starting the App the first time and tapping the UIBarButton, the master looks like the following:
After hiding and tapping the UIBarButton item the second time, the master looks like it's supposed to. It has the red divider line instead of the standard colored one:
Now, the CustomBackgroundView that is used in the UISplitViewController delegate is actually being instantiated, but somehow not used the first time around.
Any idea how I could force the UIPopOverController to use the CustomBackgroundView the first time?
I ended up simply adding a subview to the UISplitViewController's view, which has the same color as the UINavigationBar.
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
[splitViewController.view addSubview:coloredView];
Is your Split View your root view controller? It looks like you have your split view within a Navigation Controller, which is not allowed. That would explain your graphical bugs.

Call another view from button in popoverview

I have a searchcontrollerviewcontroller, detailviewcontroller and a filterviewcontroller
In Appdelegate I added the first 2 as splitview controller and delegate to detailviewcontroller like this:
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:searchViewController, detailNavigationController, nil];
when the ipad turns it shows buttons for the popoverview
- (void)splitViewController:(UISplitViewController *)splitController
willHideViewController:(UIViewController *)viewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popoverController{
UIBarButtonItem *filterbutton = [[UIBarButtonItem alloc]initWithTitle:#"Filter" style:UIBarButtonItemStylePlain target:nil action:#selector(showFilterPopover:)];
barButtonItem.title = NSLocalizedString(#"Search", #"Search results");
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:barButtonItem,filterbutton, nil] animated:YES];
self.masterPopoverController = popoverController;
}
I init the filterview in here
-(void)showFilterPopover: (id) sender{
FilterViewController *controller = [[FilterViewController alloc]initWithNibName:#"FilterViewController" bundle:nil];
UIPopoverController *popover =
[[UIPopoverController alloc] initWithContentViewController:controller];
popover.delegate = self;
self.masterPopoverController = popover;
[self.masterPopoverController
presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
But nothing happens, the popover works for the detailview but not for the filterview....
Am I forgetting something ?

How to dismiss a popover with a navigation controller?

I have an app which is divided in four views, when I tap a view the app shows a popover and that popover has a navigation controller. I can navigate between view and the data is shows correctly. But when I am in the last view and I tap a row, the popover don't dismiss (I want in didSelectRowAtIndexPath).
How could do it?
I tried in this way, I created a method that dismiss the popover and I call this method en didSelectRowAtIndexPath, but did not works.
This is the method in the main ViewController
-(IBAction)mostrarTabla:(id)sender
{
// Popover that shows the table
UIPopoverController *popover;
// RootViewController is the first view
RootViewController *rootViewController = [[RootViewController alloc] init];
// With a nav bar
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];
// Popover customitation
navBar.contentSizeForViewInPopover = CGSizeMake(20.0f, 20.0f);
popover = [[UIPopoverController alloc] initWithContentViewController:navBar];
[navBar release];
popover.delegate = self;
popover.popoverContentSize = CGSizeMake(320.0f, 832.0f);
// PopOver is shows in the view 1
[popover presentPopoverFromRect:CGRectMake(100.0f, 10.0f, 20.0f, 20.0f) inView:_view1 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I create a method in this View Controller
-(void)hidePopover
{
[self.popOver dismissPopoverAnimated:YES];
}
And in the last view I used the method but did not works
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewController *grafica = [[ViewController alloc] init];
self.indicadorId = [[self.arrayId objectAtIndex:indexPath.row] integerValue];
DataIndicador *datos =[[DataIndicador alloc] init];
datos.idIndicador = self.indicadorId;
[datos release];
[grafica hidePopover];
}
In the last view I want that the popover returns to its view and shows the data (a chart)
Thanks
The grafica instant of the ViewController is not the same as the whatever instant of VieController that was originally presented the popover.

How to hide master view in UISplitView

I'm trying to hide the master view in UISplitView in the landscape mode. This i want to do on an button click. In my navigation bar I have a button on click of which I want to hide the master view in landscape mode. Also if the master view is hidden then on click of that same button it should show the master view back. All this needs to be done in master view. I referred to the following function
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}
But it hides master view on view load in spite of button click. Below is my code for detail view
- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
[detailItem release];
detailItem = [newDetailItem retain];
// Update the view.
NSLog(#"Detail item in detail view::%#",detailItem);
NSString *imageName = [NSString stringWithFormat:#"%#.jpg",[detailItem description]];
NSLog(#"Image name is::%#",imageName);
self.imageToDisplay.image = [UIImage imageNamed:imageName];
[self configureView];
}
if (mainpopover != nil) {
[mainpopover dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
detailDescriptionLabel.text = [detailItem description];
openInButton = [[UIBarButtonItem alloc] initWithTitle:#"OpenIn" style:UIBarButtonItemStyleDone target:self action:#selector(openIn)];
favoritesButton = [[UIBarButtonItem alloc] initWithTitle:#"*" style:UIBarButtonItemStyleDone target:self action:#selector(markFavorite)];
emailButton = [[UIBarButtonItem alloc] initWithTitle:#"E" style:UIBarButtonItemStyleDone target:self action:#selector(emailFile)];
uploadButton = [[UIBarButtonItem alloc] initWithTitle:#"#" style:UIBarButtonItemStyleDone target:self action:#selector(uploadFile)];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:openInButton, favoritesButton,emailButton, uploadButton, nil];
}
#pragma mark -
#pragma mark Split view support
-(void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
{
barButtonItem.title = #"Quicksync";
self.navigationItem.leftBarButtonItem = barButtonItem;
self.mainpopover = pc;
}
// Called when the view is shown again in the split view, invalidating the button and popover controller.
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
myBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"<" style:UIBarButtonItemStyleDone target:self action:#selector(hideMasterScreen)];
self.navigationItem.leftBarButtonItem = myBarButtonItem;
self.mainpopover = nil;
}
// Called when the hidden view controller is about to be displayed in a popover.
- (void)splitViewController:(UISplitViewController*)svc popoverController:(UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController
{
// Check to see if the popover presented from the "Tap" UIBarButtonItem is visible.
if ([barButtonItemPopover isPopoverVisible]) {
// Dismiss the popover.
[barButtonItemPopover dismissPopoverAnimated:YES];
}
}
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}

Resources