UINavigationController title is not displayed? - ios

I have normal UIViewController ,inwhich I added UINavigationControllerDelegate,i
added as following in willappear?but it did not work?
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationController.navigationItem.title = #"hai";

You should set the title in the view controller you add to your navigation controller.
i.e. in the add view controller
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"My Title";
}
or access the array of your viewcontrollers directly
AddFriendViewController *addFriendsView = [[AddFriendViewController alloc] initWithNibName:#"AddFriendViewController" bundle:nil];
[self.navigationController pushViewController:addFriendsView animated:YES];
[[self.navigationController.viewControllers objectAtIndex:0] setTitle:#"myTitle"];
[addFriendsView release];

Every view controller has a navigation item. You are changing the navigation item of the navigation controller... but that will never be seen unless the navigation controller was inside another navigation controller! Instead of
self.navigationController.navigationItem.title = #"hai";
you want
self.navigationItem.title = #"hai";
or, if your navigation item's title is nil, the navigation controller will use your view controller's title:
self.title = #"hai";
You should simply set the view title, which is used by both navigation bars and tab bars, unless you want to specify a different title for each of those for some reason.

Are you sure that self.navigationController.navigationItem is not nil when you set its title?

If no viewcontroller has been pushed on the stack, ie. you're displaying the viewcontroller at the top of the stack (sometimes called rootViewController) you can do it with
[rootViewController setTitle:#"Title"];
NOTE that you must use setTitle - rootViewController.title=#"Title" will normally not work.
Actually, you can do it with any viewcontroller, even if it's not viewDidLoad'ed yet. If it's created programmatically, just create it with
myViewController *mvc=[[myViewController alloc] initWithNibName:#"nameofnibwithout.xib" bundle:nil];
Or you could declare it as an object in the app delegate, make it an IBOutlet, create a UIViewController and set its class to myViewController, and connect it to the IBOutlet so it's not nil.

You may need to set the Navigation bar to "Black Navigation Bar With Prompt" in the Attributes tab on the controller. That's what worked for me.

In my case the title was not visible on iOS6, when I set it up in the init method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = LS(#"Favorites");
self.tabBarItem.title = LS(#"Favorites");
self.tabBarItem.image = [UIImage imageNamed:#"star"];
}
return self;
}
So, it should be moved from there to ViewDidLoad.

Related

Simple Title not showing up in UINavigationController

I have looked at all of the similar/related questions, but none either a) are exactly my problem or 2) the solutions just don't work.
In my appDelegate.m I have in didFinishLaunchingWithOptions
JCGRootNavigationController *rnc = [[JCGRootNavigationController alloc] init];
self.window.rootViewController = rnc;`
JCGRootNavigationController is a subclass of UINavigationController
#interface JCGRootNavigationController : UINavigationController`
In JCGRootNavigationController.m:
#implementation JCGRootNavigationController
-(instancetype) init {
self = [super init];
self.view.backgroundColor = [UIColor lightGrayColor];
self.navigationItem.title = #"MY TITLE";
return self;
}
And the title just won't display. I see the Navigation Bar, but no title. Looks like lots of people over the years have had this same problem. Maybe a simple answer will help clear up all of the confusing. This is so incredibly frustrating.
When working with a Storyboard, setting the title of the UIViewController or UITableViewController does not seem to add that title to the Navigation Controller, as other answers suggest.
Instead, find the UINavigationItem that is likely alongside your View Controller object in the Storyboard hierarchy. Set this Navigation Item's title to apply that title to the Navigation Controller.
UINavigationController automatically shows the title of the UIViewController subclass it is displaying. It does so by looking at the navigationItem.title property of that UIViewController or UIViewController subclass. Basically UINavigationController doesn't have a title.
Thanks believesInSanta, While I cannot find this explicitly stated in apple documentation anywhere, I have to go with this being the answer. UINavigationController doesn't have a title.
To get the title to work, back in appDelegate.h I added:
JCGTableViewController *tvc = [[JCGTableViewController alloc] init];
JCGRootNavigationController *rnc = [[JCGRootNavigationController alloc] initWithRootViewController:tvc];
self.window.rootViewController = rnc;
Where JCGTableViewController is another subclass I added. As you can probably tell, it is a subclass of UITableViewController.
In JCGTableViewController I overrode init to:
-(instancetype) init {
self = [super init];
if(self) {
self.title = #"TVC";
self.view.backgroundColor = [UIColor lightGrayColor];
}
return self;
}
While I used a tableViewController, I imagine you can add any view to the NavigationController and set the properties that way. I will play around with that today.
Thanks all!

On iOS 7, pushing a controller with a toolbar leaves a gap of unusable space if it's ultimately contained within a tab bar controller

In my iOS app, my window's rootViewController is a tab bar controller with the a hierarchy like this:
UITabBarController
UINavigationController 1
FirstContentController
UINavigationController 2
...
UINavigationController 3
...
...
When the user taps a certain row on FirstContentController, an instance of SecondController will be pushed onto its navigation controller. SecondContentController sets hidesBottomBarWhenPushed to YES in its init method and sets self.navigationController.toolbarHidden to NO in viewWillAppear:.
In iOS 6, the user would tap the row in FirstController and SecondController would get pushed onto the nav controller. Because it has hidesBottomBarWhenPushed set, it would hide the tab bar and, by the time the transition animation was complete, SecondController would be on the screen with its toolbar visible.
However, when testing this under iOS 7, hidesBottomBarWhenPushed's behavior seems to have changed. What I see now is:
the tab bar hides, as expected
the toolbar appears, as expected
a gap of unusable space exactly 49 pixels tall (the height of the tab bar) appears between the toolbar and the content view
The gap is completely unusable - it doesn't respond to touches and if i set clipsToBounds to YES on the main view, nothing draws there. After a lot of debugging and examining subview hierarchies, it looks like iOS's autosizing mechanism resizes the view controller's view to a height of 411 (on the iPhone 5). It should be 460 to reach all the way down to the toolbar, but the layout system seems to be including a "ghost" 49-pixel-tall tab bar.
This problem only occurs if the view controller has a tab bar controller as one if its parent containers.
On iOS 7, how can I have the tab bar disappear and a toolbar seamlessly slide into place when a new controller is pushed, and still have the view take up the entire space between the navigation item and the toolbar?
UPDATE
After further investigation, this only happens if SecondController's edgesForExtendedLayout is set to UIRectEdgeNone. However, unless I set that property to UIRectEdgeNone, the view's frame is too long and extends under the toolbar, where it can't be seen or interacted with.
I found that adding the following 2 lines of code in viewDidLoad of SecondViewController (where you want to hide TabBar but show the tool bar) fixes the problem.
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;
My viewDidLoad of SecondViewController is as follows:
- (void)viewDidLoad {
[super viewDidLoad];
// These 2 lines made the difference
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;
// The usual configuration
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
self.navigationController.toolbar.translucent = NO;
.
.
}
But you need to fix the frame of the view manually as this causes the size to be (320x504). Which means it extends even behind the tool bar. If this is not a concern for you then this solution should work.
You will not like this answer This is not the answer you want, but after some research on hiding the tab bar in iOS7, my conclusion is: don't!
Tab bars have never been meant to be hidden - after all why have a UITabBarController if you want to hide the tab bar. The hidesBottomBarWhenPushed on view controllers is for hiding the bottom bar of a navigation controller, not tab bars. From the documentation:
A view controller added as a child of a navigation controller can display an optional toolbar at the bottom of the screen. The value of this property on the topmost view controller determines whether the toolbar is visible. If the value of this property is YES, the toolbar is hidden. If the value of this property is NO, the bar is visible.
Moreover, you are warned not to modify the tab bar object directly. Again, from the documentation:
You should never attempt to manipulate the UITabBar object itself stored in this property.
This is exactly what you are doing when setting it to hidden.
In iOS6 this has worked, but now in iOS7, it doesn't. And it seems very error prone to hide it. When you finally manage to hide it, if the app goes to the background and returns, Apple's layout logic overrides your changes.
My suggestion is to display your data modally. In iOS7 you can create custom transitions, so if it is important to you to have a push transition, you can recreate it yourself, although this is a bit over the top. Normal modal transition is something users are familiar, and actually fits this case better than push which hides the tab bar.
Another solution is to use a toolbar instead of a tab bar. If you use the navigation controller's toolbar for your tabs, you can then use hidesBottomBarWhenPushed as you require and it would give you the behavior you expect.
Uncheck "Hide bottoms bars on push" and set your autoconstraints as if there is a tab bar. Then in "ViewDidLoad" of the controller you want to hide the system tab bar, put the following code.
[self.tabBarController.tabBar setFrame:CGRectZero];
This makes sure the tab bar still accepts user interaction yet not visible to users. (other alternatives such as setting it 0 alpha or hidden will render tab bar useless) Now the autoconstaraints will make sure your view displays correctly with the tab bar height as zero.
It's a bug in iOS 7 UIKit due to this particular combination of:
UITabBarController
hidesBottomBarWhenPushed = YES
edgesForExtendedLayout = UIRectEdgeNone
UINavigationController toolbar
You should file a bug with Apple and include your sample code.
To work around the bug you need to remove one of those four conditions. Two likely options:
Fix the layout of your "second" view controller so that it works correctly when edgesForExtendedLayout is set to UIRectEdgeAll. This could be as simple as setting the contentInset on a scroll view.
Don't use UINavigationController's built-in toolbar. Instead, create a separate UIToolBar instance and manually add it to your second view controller's view.
You do have to set the tabBar of the TabBarController to hidden and your view should have autosizing set to flexible height.
With this code it's working:
#implementation SecondController
-(id)init
{
if( (self = [super init]) )
{
}
return self;
}
- (void)viewDidLoad;
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.tabBarController.tabBar.hidden = YES;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// will log a height of 411, instead of the desired 460
NSLog(#"frame: %#", NSStringFromCGRect(self.view.frame));
}
#end
Or, if you do want to use the hidesBottomBarWhenPushed method, you have to do this before you push the view controller obviously:
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
SecondController* controller = [[SecondController alloc] init];
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
If using the second method, your viewDidLoad method can get rid of flexible height method as well as tabBarHidden:
- (void)viewDidLoad;
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.edgesForExtendedLayout = UIRectEdgeNone;
}
See the result:
The key to this conundrum is that the navigationcontroller.view.frame size doesn't change. Going of batkin's Gist here is a gist of my own.
FirstViewController.m
#import "FirstController.h"
#import "SecondController.h"
#implementation FirstController
-(id)init
{
if( (self = [super init]) )
{
self.tabBarItem.title = #"Foo";
self.tabBarItem.image = [UIImage imageNamed:#"Tab Icon.png"];
}
return self;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = #"Click";
return cell;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
SecondController* controller = [[SecondController alloc] init];
self.tabBarController.tabBar.hidden = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#end
SecondViewController.m
#import "SecondController.h"
#implementation SecondController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor redColor];
self.view.clipsToBounds = YES;
/* ENTER VORTEX OF DESPAIR */
// without this, there's no gap, but the view continues under the tool
// bar; with it, I get the 49-pixel gap thats making my life miserable
self.edgesForExtendedLayout = UIRectEdgeNone;
//this resizes the navigation controller to fill the void left by the tab bar.
CGRect newFrame = self.navigationController.view.frame;
newFrame.size.height = newFrame.size.height + 49;
self.navigationController.view.frame = newFrame;
/* EXIT VORTEX OF DESPAIR */
self.navigationController.toolbarItems = #[
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:nil action:nil]
];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.navigationController.toolbarHidden = NO;
// will log a height of 411, instead of the desired 460
NSLog(#"frame: %#", NSStringFromCGRect(self.view.frame));
NSLog(#"frame: %#", NSStringFromCGRect(self.navigationController.view.frame));
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.tabBarController.tabBar.hidden = NO;
self.navigationController.toolbarHidden = YES;
//this resizes the navigation controller back to normal.
CGRect newFrame = self.navigationController.view.frame;
newFrame.size.height = newFrame.size.height - 49;
self.navigationController.view.frame = newFrame;
//this is optional and resizes the view to fill the void left by the missing toolbar.
CGRect newViewFrame = self.view.frame;
newViewFrame.size.height = newViewFrame.size.height + 49;
self.view.frame = newViewFrame;
}
#end
If you are using Auto Layout,make sure you pin the view to its superview instead of Top Layout Guide or Bottom Layout Guide.
Have you tried to move your call hidesBottomBarWhenPushed in the viewDidLoad or before the secondViewController is pushed?
With ios7, a lot of timing issues appear if you don't do the calls at teh good moment.
You mention that you can fix this by not touching the edgesForExtendedLayout. Is there a necessary reason that the content/controls of the view controller are contained in the root view of the pushed view controller? You might consider wrapping everything in a view that is the first and only child of the main view. Then adjust that view's frame in the viewDidLayoutSubviews of the pushed view controller to avoid having content permanently beneath the toolbar using the top/bottomLayoutGuide of the view controller.
I built a new project using your Gist, and I encased the UITabBarController in a UINavigationController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UITabBarController* tabController = [[UITabBarController alloc] init];
tabController.viewControllers = #[
[[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]],
[[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]]
];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tabController];
[navController setNavigationBarHidden:YES];
self.window.rootViewController = navController;
return YES;
}
And to show the SecondViewController, here is what I did:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController* controller = [[SecondViewController alloc] init];
// Reaching the UITabBarViewController's parent navigationController
[self.parentViewController.navigationController pushViewController:controller animated:YES];
}
Finally, in the secondViewController:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor redColor];
self.view.clipsToBounds = YES;
// The following line only works in iOS7
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:nil action:nil]];
UIBarButtonItem * logoutButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:nil action:nil];
NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
[self setToolbarItems:arr animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController setToolbarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
}
Here's what it does look:
EDIT: Changed the example and changed the screenshot. Made the example iOS6 compatible.
I manually manage hide/unhide of bottom-tab-bar along with fade animation by
...
[self.tabBarController.tabBar setHidden:NO];
[self.tabBarController.tabBar setAlpha:0.1];
[UIView animateWithDuration:0.2 animations:^{
[self.tabBarController.tabBar setAlpha:1.0];
}];
...
Bottom Toolbar on SecondVC was added in IB. No problem so far. Using Storyboard.
I think you can set SecondController's edgesForExtendedLayout to UIRectEdgeBottom.
This helps me:
Choose you view controller in storyboard -> Go to properties -> Uncheck "Adjust Scroll View Insets"
As #Leo Natan is pointing out, it seems as if hiding the tab bar and showing a toolbar is discouraged.
Nevertheless, there is a very easy solution that is working:
Just check "Under Opaque Bars" in the view controller properties in the storyboard as shown below:

Kal Calender Disappears when clicked Tab

When I click the tab bar that holds my kal calendar the calendar disappears:
This is my code in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
KalViewController *calendar = [[KalViewController alloc] init];
[self.navigationController pushViewController:calendar animated:YES];
calendar.dataSource = self;
calendar.delegate = self;
[calendar reloadData];
self.tabBarController.delegate = self;
}
I also have this method:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[self viewWillAppear:YES];
//Even when I comment out this line the problem stays!
}
If you need more infomation just ask.
EDIT:
You are using your tab bar controller improperly. Indeed, you should populate it with your controllers (either in Interface Builder or by setting the tab bar controller's controllers property) and let it do its job.
On another coin, note that viewWillAppear can be called multiple times, so this is the last place where you want to allocate a new controller.
If you have overridden viewWillAppear in order for your controller to show something when it s view is displayed that is not the correct approach.
EDIT:
If you create your UI programmatically, these are the steps you should follow in you application:didFinishLaunching: to setup the rootViewController:
FirstViewController *fistVC = ...
SecondViewController *secondVC = ...
ThirdViewController *thirdVC = ...
NSArray *viewControllers = [[NSArray alloc] initWithObjects:fistVC, secondVC, thirdVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllers animated:YES];
self.window.rootViewController = self.tabController;
If you build your UI in Interface Builder, you will do the same graphically, but I cannot reproduce it here.
In any case, I hope this snippet clarifies the way the tab bar controller works: you instantiate all of its controllers, put them in an array, pass the array to the tab bar controller. No need to instantiate anymore the tabbed controllers (neither in viewWillAppear nor in viewDidLoad)...

IOS tab bar names show up for other view controllers, but not for Table View Controller?

I hope you can tell me what I'm doing wrong. Also, apologies, I'm working on learning to get the code formatted right in the question.
I'm sure that will be intuitive once I know how it works:-)
Thank you.
I am working on creating a sample app in the style of iPhotos - one that has 4 tab bars at the bottom of the window and where the first view that comes up is a UITableViewController, it comes up with those directional arrows at the end of each row/instance, user can click on any of them and get more detail about that instance. That first view is called ItemsViewController. It has a blank tab bar button associated with it in the tab bar, and I can return to it. The other 3 tab bar items are all regular UIViewController's, in my sample they each just bring up an image and that's all they do (for now).
I have finally managed to get all 3 UIViewController and the one UITableViewController to exist and work in the same app. (hooray!) and I can get names to show up on each of the 3 tab bar items that are not the table view controller. But I cannot get the UITableViewController.m to display a name on it's tab bar item in the tab bar.
....... This is the code I use in the app delegate method ....
`- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tabBar = [[UITabBarController alloc] init];
ChairGarden* vc1 = [[ChairGarden alloc] init];
JSerra* vc2 = [[JSerra alloc] init];
Angel* vc3 = [[Angel alloc] init];
// Create aN ItemsViewController
ItemsViewController *itemsViewController = [[ItemsViewController alloc] init];
// Create an instance of a UINavigationController
// its stack contains only itemsViewController
UINavigationController *vc4 = [[UINavigationController alloc]initWithRootViewController:itemsViewController];
NSArray* controllers = [NSArray arrayWithObjects:vc4, vc1, vc2, vc3, nil];
tabBar.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Place navigation controller's view in the window hierarchy
[[self window] setRootViewController:tabBar];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
`
..... This is a snippet of code I use in one of the regular UIViewController's that specifies a tab bar title. I see the title 'Chair Garden' on the tab bar, and it brings up the right image. The other two regular ones work the same way
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// get tab bar item
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:#"Chair Garden"];
}
return self;
}
...... I have tried to make a tab bar item with a title for the first view that comes up - my UITableViewController called 'ItemsViewController', but it doesn't come up. I've tried putting it in both the init and the initWithNibName:bundle (did I specify that method name right?) (I also tried them separately). In both cases my NSLog statements show me I was there, but the tab doesn't get a title on it
#implementation ItemsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSLog (#"Getting to initWithNibName in ItemsViewController");
// get tab bar item
UITabBarItem *tbi = [self tabBarItem];
// This dosn't show up
[tbi setTitle:#"Table View"];
}
return self;
}
- (id)init
{
// Call the superclass's designated initializer
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
NSLog (#"Getting to init in ItemsViewController");
// get tab bar item
UITabBarItem *tbi = [self tabBarItem];
// This dosn't show up EITHER
[tbi setTitle:#"HOME"];
I'm not sure why this works differently for a UITableViewController vs a UIViewController (I was able to duplicate what you were seeing). However, you can set the title of the table view controller itself in the init method, and that will show up on the tab bar item (by default, a tab bar item displays the controller's title).
write
self.title=#"some name";
in viewDidLoad method instead of initWithNibName

ipad UIPopoverController with UINavigationController

How can I create a UIPopoverController with integrated UINavigationController so I will be able to slide views inside the UIPopoverController left-right (with navigation bar).
UPDATE:
I open popup like this
- (void)showSettingsViewAtSenderForIPad:(id)sender
{
if (!settingsPopoverController_)
{
SettingsPopoverController *settings = [[SettingsPopoverController alloc] init];
settings.valuesGeneratorOptions = valuesGeneratorOptions_; // setting variables
self.settingsPopoverController_ = [[[UIPopoverController alloc] initWithContentViewController:settings] autorelease];
[settingsPopoverController_ setDelegate:self];
[settingsPopoverController_ setPopoverContentSize:CGSizeMake(320, 480)];
[settings release];
}
if (!infoPopoverController_.popoverVisible)
{
[settingsPopoverController_ presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
}
I created a controller which has a NSTableViewController as a root controller in UINavigationController
#interface SettingsPopoverController : UIViewController
{
ValuesGeneratorOptions *valuesGeneratorOptions;
IBOutlet SettingsViewController *settingsViewController;
IBOutlet UINavigationController *navigationController;
}
...
#implementation SettingsPopoverController
...
- (void)viewDidLoad
{
self.settingsViewController.valuesGeneratorOptions = self.valuesGeneratorOptions;
[self.view addSubview:self.navigationController.view];
[super viewDidLoad];
}
...
end
The problem is, that the table is not scrollable inside the popup. It also ignores the table style (initWithStyle not called).
Fix?
SOLUTION:
Found the solution: popOver table view
You create a new nib and a UIViewController. This nib has, as it's top level view, a plain jane UIView and a UINavigationController. The UINavigationController's top UIViewController is whatever view controller you want to display first.
You then display this nib inside your popover controller. In the view did load, you do something like this:
-(void)viewDidLoad
{
[self.view addSubview:self.navigationController.view];
}
This adds your navigation controller's view to your view in your nib, which allows it to be displayed.

Resources