UISearchController SearchBar Overlapping Status Bar and Whitespace - uisearchcontroller

I have a view controller with a search button as the navigation item's right bar button item. When the search button is pressed, I want the a UISearchController to be presented. Here is the relevant code:
#interface BaseViewController ()
#property (nonatomic, strong) UISearchController *searchController;
#property (nonatomic, strong) UIBarButtonItem *searchBarButtonItem;
#property (nonatomic, strong) UIBarButtonItem *accountBarButtonItem;
#property (nonatomic, strong) UITableViewController *searchResultsController;
#end
#implementation BaseViewController
- (instancetype)init {
if (self = [super init]) {
UIImage *accountIcon = [UIImage imageNamed:#"account-male-icon#2x.png"];
UIBarButtonItem *accountBarButtonItem = [[UIBarButtonItem alloc] initWithImage:accountIcon style:UIBarButtonItemStylePlain target:self action:#selector(accountButtonPressed:)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:#selector(searchButtonPressed:)];
[self setSearchResultsController:[[UITableViewController alloc] init]];
[self setSearchController:[[UISearchController alloc] initWithSearchResultsController:[self searchResultsController]]];
[[[self searchResultsController] tableView] setDataSource:self];
[[[self searchResultsController] tableView] setDelegate:self];
[[[self searchResultsController] tableView] setTableHeaderView:[[self searchController] searchBar]];
[[self searchController] setSearchResultsUpdater:self];
[[self searchController] setDelegate:self];
[[self searchController] setHidesNavigationBarDuringPresentation:YES];
[[self searchController] setDimsBackgroundDuringPresentation:YES];
[[[self searchController] searchBar] setDelegate:self];
[self setDefinesPresentationContext:YES];
[self setSearchBarButtonItem:searchBarButtonItem];
[self setAccountBarButtonItem:accountBarButtonItem];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[[self navigationItem] setLeftBarButtonItem:[self accountBarButtonItem]];
[[self navigationItem] setRightBarButtonItem:[self searchBarButtonItem]];
}
- (IBAction)searchButtonPressed:(id)sender {
[self presentViewController:[self searchController] animated:YES completion:nil];
}
When the search button is pressed, the searchController gets presented. All is well, except the following two things occur:
1.) The search bar overlaps the status bar
2.) There is white space in the first row of the table view
Below are pictures illustrating the problem:
How do I resolve the status bar issue and remove the white space in the first row?

Related

iOS 6.1 - How do I implement imagePickerControllerDidCancel for a non-modal UIImagePickerController

On iOS 6.1, I am displaying a UIImagePickerController non-modally in one tab of a UITabBar.
In my init:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
[self.view addSubview:self.picker.view];
I have implemented:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
return;
}
Since I never called:
[picker presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion];
I shouldn't need to call:
[picker dismissViewControllerAnimated:NO completion:nil];
But, when I press the Cancel button, the Cancel button is grayed out and the UIImagePickerController seems to lock up. Some of the controls work, like the image/video switch and the reverse camera button, but the button to take a picture is frozen.
If I go to a different tab and return to the Camera tab, the UIImagePickerController is reset and fine again. The only code executed in this case is viewWillAppear and viewDidAppear which shouldn't have anything relevant to this situation.
On iOS 7,nothing locks up when the Cancel button is pressed.
Since the UIImagePickerController is always displayed in the tab, I don't really have a need for a cancel button so how would I either:
Hide or disable the Cancel button
Implement imagePickerControllerDidCancel so things do not lock up
Implemented a Camera Overlay View and things work fine.
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
self.picker.showsCameraControls = NO;
UIView *clearView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
clearView.opaque = NO;
clearView.backgroundColor = [UIColor clearColor];
UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-self.tabBarController.tabBar.frame.size.height-55, self.view.frame.size.width, 55)];
toolBar.barStyle = UIBarStyleBlackOpaque;
NSArray *items=[NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:#selector(takePicture)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
nil];
[toolBar setItems:items];
UIView *overlayView = [[UIView alloc] initWithFrame:self.view.bounds];
[overlayView addSubview:clearView];
[overlayView addSubview:toolBar];
[self.picker setCameraOverlayView:overlayView];
[self.view addSubview:self.picker.view];
[[UIBarButtonItem alloc] ... action:#selector(takePicture)],
- (void)takePicture
{
[self.picker takePicture]; // triggers didFinishPickingMediaWithInfo
}
UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (image != nil)
{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
}

UIPopoverController not dismissing in xCode 5/ios7

Since upgrading to iOS 7 and xCode 5 my popovers are not dismissing when the user selects an item. They have to tap outside of the popover to get it to go away.
In the following the UITableViewController is foundPatientsViewController and I am creating the propover like this from my root view controller...
TodaysPatientsViewController *foundPatientsViewController =[[TodaysPatientsViewController alloc] init];
foundPatientsViewController.patientList = patientList;
foundPatientsViewController.delegate = self;
foundPatientsViewController.patientNameOnly = YES;
UIPopoverController *foundPatientsPopOver = [[UIPopoverController alloc] initWithContentViewController:foundPatientsViewController];
foundPatientsPopOver.delegate = self;
foundPatientsViewController.myPO = foundPatientsPopOver;
[foundPatientsPopOver presentPopoverFromBarButtonItem:findPatientButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[foundPatientsPopOver setPopoverContentSize:CGSizeMake(300, popOverHeight) animated:NO];
[foundPatientsViewController release];
In foundPatientsViewController I have...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[myPO dismissPopoverAnimated:YES];
[self.delegate patienSelectedForDisplay:self withPatientNumber:[patientNumbers objectAtIndex:indexPath.row] patientName:[patients objectAtIndex:indexPath.row]];
}
What has changed?
Thanks,
John

navigation inside tabbar which is called modally from a didSelectRowAtIndexPath

I am creating an app as follows- when the app starts a tableview is displayed. I am creating this programmatically. On selecting a particular row i do a presentModalViewController to display my tabbar class which i created programmatically.
ViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ShowOptionInTab *showTabbar = [[ShowOptionInTab alloc] initWithNibName:#"ShowOptionInTab" bundle:nil];
UINavigationController *mynavController = [[UINavigationController alloc] initWithRootViewController:showTabbar];
[self presentModalViewController:mynavController animated:YES];
[showTabbar release];
}
ShowOptionsInTab.m class
#implementation ShowOptionInTab
-(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissTabbar:)];
self.navigationItem.rightBarButtonItem=doneButton;
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0, 0, 320, 460);
BuyerViewController *buyerController = [[BuyerViewController alloc] init ];
buyerController.navigationItem.title=#"Buyer";
buyerController.title=#"Buyer";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
SellerViewController *sellerController = [[SellerViewController alloc] init];
sellerController.navigationItem.title=#"Seller";
sellerController.title=#"Seller";
LenderViewController *lenderController = [[LenderViewController alloc] init];
lenderController.navigationItem.title=#"Lender";
lenderController.title=#"Lender";
tabbarController.viewControllers = [NSArray arrayWithObjects:buyerController,sellerController,lenderController, nil];
[self.view addSubview:tabbarController.view];
[sellerController release];
[buyerController release];
[lenderController release];
}
-(void)dismissTabbar:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
My ShowOptionsInTab class is a subclass of UIViewController
I have 3 tabs Buyer, Lender and Seller. Each tab has buttons which navigate to a different UIViewController page. Suppose i have 'ButtonA' and 'ButtonB' in my Buyer tab class. The problem i am facing is that i cannot navigate on the buttons present in Buyers tabs(or any other tabs). It doesnt push to the next class which 'ButtonA' should load. It also has a "Done" button on navigation bar which will dismiss the modal view and display my table view.
What am i doing wrong? if i add these tabs to localNavigationController object which i create in my ShowOptionsInTab.m class i get 2 Navigations Bars.
I got the solution. I made 3 local navigationController object and added each of my tabbar class as its rootviewController.

How to add right button on UINavigationbar in UITabbar

I have a problem when add a right button on uinavigationbar. My Nib organizer like this:
CustomTabViewController :UIViewController
-->CustomTableViewController1 : UIViewController
-->CustomTableViewController2 : UIViewController
CustomTabViewControllers are in Tabbar items
I need to save the inputs, I can add navigation item from Navigation Controller, but I can't add them from View Controller when they are childs in Tabbar items.
here is my code:
#interface CustomTabViewController : UIViewController <UITabBarDelegate> {
NSArray *detailViews;
IBOutlet UITabBar *tabBar;
IBOutlet UITabBarItem *tabBarItem1;
IBOutlet UITabBarItem *tabBarItem2;
UIViewController *selectedViewController;
}
#property (nonatomic, retain) NSArray *detailViews;
#property (nonatomic, retain) IBOutlet UITabBar *tabBar;
#property (nonatomic, retain) IBOutlet UITabBarItem *tabBarItem1;
#property (nonatomic, retain) IBOutlet UITabBarItem *tabBarItem2;
#property (nonatomic, retain) UIViewController *selectedViewController;
#end
#implementation TabViewController
#synthesize detailViews;
#synthesize tabBar;
#synthesize tabBarItem1;
#synthesize tabBarItem2;
#synthesize selectedViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil number:(NSString *)num{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
CustomTableViewController1 *tVC1 = [[CustomTableViewController1 alloc]initWithNibName:#"CustomTableViewController1" bundle:nil];
CustomTableViewController2 *tVC2 = [[CustomTableViewController2 alloc]initWithNibName:#"CustomTableViewController2" bundle:nil];
NSDictionary *detail = [[[Services sharedInstance] getDetail:num] copy];
[tVC1 setDetail:detail];
[tVC2 setDetail:detail];
NSArray *array = [[NSArray alloc] initWithObjects:tVC1, tVC2, nil];
self.detailViews = array;
[self.view addSubview:tVC1.view];
self.selectedViewController = tVC1;
[array release];
[TVC release];
[TVC release];
[detail autorelease];
}
return self;
}
// ....
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item == tabBarItem1) {
CustomTableViewController1 *tVC1 = [detailViews objectAtIndex:0];
[self.selectedViewController.view removeFromSuperview];
[self.view addSubview:tVC1.view];
self.selectedViewController = tVC1;
} else if (item == tabBarItem2) {
CustomTableViewController2 *tVC2 = [detailViews objectAtIndex:1];
[self.selectedViewController.view removeFromSuperview];
[self.view addSubview:tVC2.view];
self.selectedViewController = tVC2;
}
}
#end
the Custom Table View Controllers are inside the tab bars with some default value which need to be change by user and save. I can add a right button on uinavigationbar from my TabViewController class but it can not rich the information inside CustomTableViewController in tab bars. Is there any way to add a right button on uinavigationbar from Custom Table View Controller which I have? Can you show me the solution?

UILabel to NSString to load webview

So I have this code, where I am sending a variable storyLink to a label and display it in the specified nib. So far the label displays the text which is what I want. But I want to use that text as an url for a webview. urlString = nothing as of right now because I can't figure out how to use/convert an UILabel to a String suitable for a webview url. So if that was confusing basically I want to take the text stored in my label and use it for the url in my webview. Can someone help?
TestView.h
#interface TestView : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIWebView *webView;
NSString *urlString;
}
#property(nonatomic, retain)IBOutlet UILabel *label;
#property(nonatomic, retain)IBOutlet UIWebView *webView;
#property(nonatomic, retain)NSString *urlString;
#end
TestView.m
- (void)viewDidLoad {
[super viewDidLoad];
label.text=nil;
urlString=something;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
sending code
TestView *objFirstController=[[[TestView alloc] initWithNibName:#"TestView" bundle:nil] autorelease];
[self.navigationController pushViewController:objFirstController animated:YES];
objFirstController.label.text=storyLink;
When setting properties that are accessed during 'viewDidLoad', make sure to put them before you use pushViewController.
TestView.m
- (void)viewDidLoad
{
[super viewDidLoad];
label.text=urlString;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}
sending code
TestView *objFirstController = [[[TestView alloc] initWithNibName:#"TestView" bundle:nil] autorelease];
objFirstController.urlString = storyLink;
[self.navigationController pushViewController:objFirstController animated:YES];

Resources