I am using a uipopover controller with navigation bar.Actually i want to have navigation bar inside the popover controller. i tried changing the background color of the navigation controller but it didnt look as i expected.The navigation bar buttons seems to be attached with the popover corners.Please find the screenshot attached.Below is my code which i used to create the popover.
WLViewBookmarkViewController * viewBookmarkViewController = [[WLViewBookmarkViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewBookmarkViewController.delegate = self;
UINavigationController *viewBookmarkNavController = [[UINavigationController alloc] initWithRootViewController:viewBookmarkViewController];
viewBookmarkNavController.navigationBar.backgroundColor = [UIColor colorWithRed:9/255.0 green:135/255.0 blue:46/255.0 alpha:1.0];
self.bookmarkPopoverController = [[UIPopoverController alloc] initWithContentViewController:viewBookmarkNavController];
[self.bookmarkPopoverController presentPopoverFromBarButtonItem:bookmarkButtonItem permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
Please suggest if there are any other way to achieve this.
I would init the UIPopover controller with the UINavigationController directly
self.bookmarkPopoverController = [[UIPopoverController alloc] initWithContentViewController: viewBookmarkNavController];
Also try settings the content size of the popover by overriding -contentSizeForViewInPopover in the viewBookmarkViewController class to return a CGSize, you should get neater results this way.
I created a Xib in where i had a view for the controller which i had to add inside the popover.i added a table view and a navigation bar into the view.
Related
I have an apps with UISplitViewController as Root View, but for children of this view I use UINavigationController.
Although Master and Detail View is UIViewController, but I added this to UINavigationController before I set as Child of UISplitViewController, I did this because I need Title and UIBarButton, and also because I share this view for iPad and iPhone.
So this the snippet of my code:
MasterView _masterView = new MasterView;
UINavigationController _masterViewNavigation = new UINavigationController(_masterView);
DetailView _detailView = new DetailView;
UINavigationController _detailView Navigation = new UINavigationController(_detailView);
_splitView.ViewController = new UIViewController[]{_masterView, _detailView};
Everything was working before iOS 13. But when I run on iOS 13, ViewDidLoad of _masterView wasn’t called. While I need this to change image view on _masterView when the user makes changes on _detailView, although _masterView not shown.
Also WillHideViewController is not called, while I need this to add UIBarButtonItem on _detailView to show and hide _masterView.
Can you help me to find the solution?
Issue with iOS 13 Split view controller using IB. If you have navigation controller embedded to Master/Detail view controller it just loads the navigation controller.
To fix that issue create a custom class from UISplitViewController and assign that to your splitviewcontroller in storyboard and programatically add Navigation controller and masterViewcontroller to that UISplitViewController. That should load your view properly. This code goes in the viewdidload or willappear of the UISplitviewcontroller class.
Sample code. in Obj c
MasterViewController *master = [[MasterViewController alloc] init];
UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *navC = [[UINavigationController alloc] init];
self.viewControllers = [NSArray arrayWithObjects:tableViewNavigationController,navC, nil];
This fixed my issue , Had similar issue after iOS13. Hope that help !
Trying to set a NavBar programaticaly, and my title isn't showing in the navbar. Any ideas as to whats happening?
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
navbar.topItem.title = #"My accounts";
[self.view addSubview:navbar];
The problem here is your use of the UINavigationBar.
Read the documentation for UINavigationController programming here.
You should not be creating your own UINavigationBar and adding it as a subview to your view controller's view.
The correct thing to do is to create a UINavigationController and add your view controller to its stack.
So something like this:
CustomViewController *myViewController = ...// whatever initialization you do
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];
Each view controller has its own UINavigationItem that the navigation controller uses to set up the navigation bar's view when that view controller is at the top of the stack.
So in your CustomViewController.m, possibly in the init method or in viewDidLoad,
you can set up the navigation item by doing something like this:
self.navigationItem.title = #"whatever";
self.navigationItem.rightBarButtonItem = ...// create a UIBarButtonItem and set it here if you want a button on the right side of the navigation bar
So once again, you do not touch the navigation bar directly or add it to your view hierarchy. The UINavigationController handles all of that for you.
Use
self.navigationItem.title = #"the title";
as setting navBar.topItem.title will not work in all circumstances.
Adding tab bar controller to the UIView by [self.view addSubview:tabBarController.view];
is not loaded the content view controllers view, while selecting the tab bar items it crashed. When set the tab bar controller to the root view controller its working fine. How to set tab bar controller into UIView so that I can set another view for some other purpose like iAd?
You just create one tabbar controller in app delegate but don't add it to window, and in view controller you have just add these:
gObjAppDelegate.tabBarController = [[UITabBarController alloc] init];
gObjAppDelegate.tabBarController.viewControllers = #[viewController1, viewController2];
[gObjAppDelegate.tabBarController setSelectedIndex:0];
[self.navigationController pushViewController:gObjAppDelegate.tabBarController animated:YES];
gObjAppDelegate is shared singleton instance of app delegate.This way it worked for me.
I have made popover displaying UITableViewController, that is used for navigation. What I am interested in to know is - can you use navigational controller inside popover. Lets say you have table where each row transitions to new view. Can this be used in conjuction with popover view, and if so, can you provide some working examples?
Yes, it's very much possible. Firstly create the object of your table class.
TableClass *tblClassObj = [[TableClass alloc] init];
Then create the navigation controller object.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tblClassObj];
Then use this navigatin controller for your pop over controller.
UIPopoverController *samplePopOver = [[UIPopoverController alloc] initWithContentViewController:navigationController];
...
Don't forget to release the objects.
I have created a tab bar controller as follows:
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
NSMutableArray *tabsArray = [[NSMutableArray alloc] init];
//tab1: dive info
LogsDetailDive *logsDetailDive = [[LogsDetailDive alloc] initWithNibName:#"LogsDetailDive" bundle:nil];
[logsDetailDive initWithLogSelected:logSelected:siteSelected];
logsDetailDive.title = #"Info";
logsDetailDive.tabBarItem.image = [UIImage imageNamed:#"/images/logs.png"];
[tabsArray addObject:logsDetailDive];
//tab2: deco info
...
//tab3: equipment info
...
//tab3: computer info
...
tabBarController.viewControllers = tabsArray;
[logsDetailDive release];
[self.view addSubview:tabBarController.view];
This tab controller is pushed from a previous table view into the navigation controller.
What I'm trying to get now is to show another view pushed from a tableview in LogsDetailDive, but I really cannot understand what I am missing, since it doesn't work.
Can you suggest something?
Thanks
UITabBarController reference
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
So the bottom line, this should not be done, and will cause some problems. If you need a tabbar layout you should instead use a toolbar.