UINavigationbar Prompt overlaps the screen content - iphone

ran into a weird issue. If I set the prompt on the navigation controller, navbar overlaps the content of the screen. What is the proper way of dealing with this?
-(id)initwithsomestuff:(stuff)
{
...
self.title = #"My Title";
self.navigationItem.prompt = "#Prompt";
...
}
When this view controller is pushed on, it first appears, then it resizes it's navigation bar to show the prompt in it. But that has a nasty side effect of not resizing the screen content below and covers a good amount of stuff I actually need on the screen.
What's a preferred way of handling this issue? Layout is in xib if that helps.

One problem you have is your init function needs to call super. Following your example, it would look like this:
- (id)initWithSomeStuff:(id)stuff
{
self = [super init];
if (self) {
self.title = #"My Title";
self.prompt = #"Prompt";
}
return self;
}
Next, are you developing against iOS 7? It is intended behavior to cover the content with the navigation bar by default. If you want to suppress this behavior, perform the following on your view controller:
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
You can also set these on the View Controller in the Story board. They are shown on the Properties tab, under Extend Edges.

Related

Create a custom UISearchDisplayController programmatically

I was able to create an app using Storyboard - it has a navigation controller containing a table view controller with a search display controller and worked as expected.
I then decided to customize it by adding a UIButtonBarSystemItemSearch (magnifying glass) to the navigator bar so that when touched it would display the search bar over the navigator bar, just like setDisplaysSearchBarInNavigationBar does. To do this I removed the UISearchDisplayController from the storyboard and added it programmatically as shown in the code below. The btnSearchClicked function is called when the magnifying glass is touched, so the button is hooked up right.
My project is very similar to the Apple example project "AdvancedTableSearch" but without the scope bar.
- (IBAction) btnSearchClicked:(id)sender
{
//Set up search bar
UISearchBar *mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[mySearchBar setDelegate:self];
[mySearchBar setShowsCancelButton:YES animated:NO];
// Set up search display controller
UISearchDisplayController *mySearchController = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self];
mySearchController.delegate = self;
mySearchController.searchResultsDataSource = self;
mySearchController.searchResultsDelegate = self;
//mySearchController.displaysSearchBarInNavigationBar = YES;
mySearchController.navigationItem.titleView.opaque = NO;
[self.navigationController.navigationBar addSubview:self.searchDisplayController.searchBar];
}
I am having two problems with this approach. The most important one is that even though I set the delegate properties, when I type into the search bar none of my delegate functions are called (specifically shouldReloadTableForSearchString).
The second problem is that the cancel button doesn't display despite calling the setShowsCancelButton method.
I've been learning iOS for the last year and reading everything I can find on SO, but can't figure this one out. This is my last resort and I will fall back to the old storyboard approach with standard search bar if I must. The reason I like this other approach is that I have a very long list of contacts (~5000) and don't want to have to scroll to the top to get the search bar.
Looks like you're not adding the right searchDisplayController? you added self.searchDisplayController but inited a mySearchController. Try putting the last line as:
[self.navigationController.navigationBar addSubview:mySearchController.searchBar];

NavigationBar hides TableView in TabBarViewController

I have a ViewController that Pushes a TabBarViewController. Inside that TabBar View Controller I have 4 tabs. Two of these tab bars are UITableViewControllers and the other two are ViewControllers. The first tab is a table view controller and is working fine, ie not being hidden by the navigation bar. The third tab, which is another TableViewController, is being partially covered by the navigation bar. The first section and first cell is being hidden underneath the navigation bar. Has anyone had this problem in the past or does anyone know a solution to this? I've tried a couple of things like resizing the frame size manually
self.tableView.frame = CGRectMake(10,10,self.view.bounds.size.width -20, self.view.bounds.size.height-20);
That did't seem to work. I tried AutoLayout as well and didn't work. I don't know what else to do. Anyone have any suggestions or ideas of how to tackle this.
Edit: I've tried the edgesForExtendedLayout but it is making my navigationbar a darker color. It animates the color change in the navigationbar, sort of like a loading bar.
Note: This is only happening in ios7. I just simulated it in iOS 6.1 and the navigationbar does not cover the table view controller at all, which is weird to me. Any one have any suggestions?
Edit #2: Noticing that this is an iOS 7 > problem i did the following but now the navigation bar has changed color to a darker color.
if([[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:#"."][0] intValue] >= 7)
{
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = YES;
self.automaticallyAdjustsScrollViewInsets = NO;
}
}
In the viewDidLoad method of UITableViewController (assuming it's loaded with a call to the tabBarController) that is associated with the tabs use
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
}
I fixed that with:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
viewcontroller.edgesForExtendedLayout = UIRectEdgeNone;
viewcontroller.extendedLayoutIncludesOpaqueBars = NO;
viewcontroller.automaticallyAdjustsScrollViewInsets = NO;
}

Scroll to top when tapping the status bar

I got a view controller (lets call it MainViewContoller) that's present 3 different tables (one in a time), user can tap a segment control to switch between those tables.
To present those 3 tables, MainViewContoller has 3 other view controllers (A, B and C), each has a UITableView as a subview and handle it's own data.
When a MainViewContoller is loaded, it initiate controllers A, B and C, and add their tableViews to it's view:
- (void)viewDidLoad {
[super viewDidLoad];
ViewControllerA *vcA = [ViewControllerA alloc] init];
[self.view addSubview:vcA.view];
ViewControllerB *vcB = [ViewControllerB alloc] init];
[self.view addSubview:vcB.view];
ViewControllerC *vcC = [ViewControllerC alloc] init];
[self.view addSubview:vcC.view];
}
So for example when user tap the segment control and choose A, the MainViewContoller hide tables B and C, and unhide table A. Something like this:
if (userTapOnA) {
self.viewControllerA.tableView.hidden = NO;
self.viewControllerB.tableView.hidden = YES;
self.viewControllerC.tableView.hidden = YES;
}
The problem:
When user tap the status bar I want that the current visible table will scroll to top.
This behavior is pretty basic and one gets it for free when using a regular view controller, but as you can see my view controller is not regular.
I suppose that by using other controllers view as MainViewContoller view I break the default behavior, so my MainViewContoller doesn't handle the status bar tap.
Someone got an idea how to solve that?
This is directly from the UIScrollView header file:
/* When the user taps the status bar, the scroll view beneath the
touch which is closest to the status bar will be scrolled to top, but
only if its scrollsToTop property is YES, its delegate does not
return NO from shouldScrollViewScrollToTop, and it is not already at
the top. On iPhone, we execute this gesture only if there's one
on-screen scroll view with scrollsToTop == YES. If more than one is
found, none will be scrolled. */
#property(nonatomic) BOOL scrollsToTop; // default is YES.
So in your case, set all scrollsToTop to NO, except the one you want to enable at that particular moment.
You should register your nested controllers as child controllers.
[self addChildViewController:vcA];
[self addChildViewController:vcB];
[self addChildViewController:vcC];
I'm not sure if this will help to solve your issue, but that's the right way to do it.

Tab Bar controller is not accessible

I have created a tab based application for iphone. when the 1st tab presses a first view will present. this view contains a button, on pressing it another view loads.
Code is:
-(IBAction)buttonPressed: (id) sender
{
Cities *cv=[[Cities alloc] initWithNibName:#"Cities" bundle:nil];
cv.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:cv animated:YES];
[cv release];
}
Now problem is that this view is loading in whole screen so that I am not able to access tab bar.
I have set the frame for this view and the view is loading in this frame,
-(void)viewWillAppear:(BOOL)animated
{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, 400);
}
but in remaining part white screen is appearing means tab bar is not accessible.
I want that whatever will be load at any time tab bar should be always accessible.
Please help me out.
Add
cv.modalPresentationStyle = UIModalPresentationCurrentContext;
Have you tried using UINavigationController inside your tabbar to dig inside your UIViewControllers??
for Ref : Adding NavigationController to Tabbar
do you really need a viewController Class for what you are trying to display??
if der's no core functionality being used, i think it will be much easier with UIView.
Happy Coding :)

How to implement a search bar that stays always on top using UISearchDisplayController in iPhone SDK 3.0

The iPhone SDK 3.0 has this handy new class "UISearchDisplayController" which makes it easy to create a search bar, handling all the user input and displaying the search results.
I am using it for my new app, but there is one thing i would like to change:
As a default, the search bar should be put at the top of the UITableView that displays the search results. So when scrolling down the result list, the search bar disappears.
What I would like to achieve is having the search bar always on top and when scrolling the TableView, the search bar should stay where it is. (Reason for this: in my app there are sometimes a lot of search results, so sometimes the user has to scroll down a while, and when he realizes that he has to change his search string, i don't want to force him to scroll all the way back)
What i already did is adding the search bar to the view of the UINavigationController which is the "parent view" of my table view, instead of adding it to the table view directly:
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
[searchBar sizeToFit];
CGFloat searchBarHeight = [searchBar frame].size.height;
CGRect mainViewBounds = delegate.navController.view.bounds;
[searchBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + 20,
CGRectGetWidth(mainViewBounds),
searchBarHeight)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[delegate.navController.view addSubview: searchBar];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar: searchBar contentsController: self];
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
... but here my problem is, that the table view stays behind the search bar, and there is always the first TableViewCell of the search results, that is hidden behind my search bar.
Is there a way to resize the UITableView of my UITableViewController permanently, so that it starts right under the search bar?
And there's another problem: Everytime i touch the search bar, the UISearchDisplayController automatically hides the Navigation Bar and resizes the UITableView (it expands to the top), so i think that at this point the UISearchDisplayController will have a big problem with my custom sized TableView...
Thanks a lot for any help!!
I don't have a solution off the top of my head - but I will say the concern you have seems to minimized by the ability for the user to simply tap the top of the screen and have the table zoom to the top (to change search terms if it's wrong).
My general solution for having bits on the page that I don't want to scroll, is to have the UITableView inside another view. That outer view contains two things -- a bar at the top, and a slightly-shorter-than-full-page table below it.
#interface:
UISearchDisplayController < UISearchBarDelegate > *searchDisplayController;
#implementation:
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar: searchBar contentsController: self];
searchDisplayController.delegate = self;
searchBar.delegate = searchDisplayController;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
Put this code in your TableViewController:
self.tableView.frame = CGRectMake(0,searchDisplayController?.searchBar.bounds.size.height,320,480);