Removing UINavigationItem prompt making black space on bottom of navigation bar - objective-c

I have view controller in my storyboard with prompt text line but when I'm pushing a new view controller without prompt line in the navigation bar i get this (see picture) black space between the navigation bar and the view controller main view.
i already tried to remove the prompt using this:
[self.navigationItem setPrompt:nil];
but i still having this problem.

Here is a work-around for setPrompt. It doesn't animate, so it I'm calling it a work-around instead of a solution. Must be in viewDidAppear, not viewWillAppear.
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// This is needed for apple bug with self.navigationItem.prompt
[self.navigationController.navigationBar setNeedsUpdateConstraints];
}

I was running into the same issue, removing the prompt in viewWillDissapear before the next view is presented worked for me:
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[self navigationItem] setPrompt: nil];
}

Related

Toggle edit button to done

Been trying to get the button to change from "edit" to "done". I am doing a tutorial and it seems to work on their end but not mine. I can't seem to find the issue.
The code:
- (IBAction)onEditButtonTapped:(UIBarButtonItem *)sender {
[self.tableView setEditing:true animated:true];
sender.style = UIBarButtonItemStyleDone;
sender.title = #"Done";
}
You are doing it the hard way. UIViewController already provides such a button.
Lets assume you want this button on the right side of the navigation bar.
In viewDidLoad, you want:
self.navigationItem.rightBarButtonItem = [self editButtonItem];
Then to handle the button, simply override the setEditing:animated: method:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
The button returned by the editButtonItem method is setup to call the setEditing:animated: method for you. There's no setup required.
I assume this means you have added your own table view to a UIViewController. If you are using a UITableViewController then you don't need the call to self.tableView setEditing... since it is already done for you.
If you really want to use your own button. Make sure you set the possibleTitles property of the UIBarButtonItem.

UINavigationBar disappears iOS7

I have some wierd bug with UINavigationBar.
Sometimes it just disappears (actually if you move view to the half of screen, and then just release it)
Video example
In the first ViewController's viewWillAppear: method i call:
[self.navigationController setNavigationBarHidden:NO animated:YES];
The second ViewController's viewWillAppear: contains:
[self.navigationController setNavigationBarHidden:YES animated:NO];
I tried change animated: parameter, but it doesn't help.
Is it iOS7 bug or I just doing something wrong?
I found the reason for this.
That's happened because in info.plist
View controller-based status bar appearance is equal to YES
If change it to NO, then all will be fine
I got the same problem, and fixed it. the solution is:
Modify info.plist, set "View controller-based status bar appearance " to NO;
Delete all - (UIStatusBarStyle)preferredStatusBarStyle {} ;
If your view controller has different status bar style, use [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
e.g. in viewWillAppear set to light, in disappear ,set to dark style.
You should define appearance per navigation controller.
If you want to have a navigation bar on the second controller only you should do the following in that particular controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
That way it will event work if you would need to change order of your controllers.

Hide status bar in iOS7

I need to hide the status-bar on iOS7. I already tried to set:
Status bar is initially hidden
and
View controller-based status bar appearance
into the plist file. Status-bar doesn't appears when app in launched, but when I change view-controller (is a tabbed app) status-bar appears!
I already tried to set
- (BOOL)prefersStatusBarHidden
{
return YES;
}
and
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
in a view-controller, but doesn't works. Any ideas?
Thank you in advance :)
UPDATE
I partially resolve the issue by setting "View controller-based status bar appearance" to "YES" into info.plist and calling the method
- (BOOL)prefersStatusBarHidden
{
return YES;
}
into the view-controller. But now I got another problem: status-bar appears when I launch another controller (UIImagePickerController). I tried to set [myPicker prefersStatusBarHidden]; but it seems to be read-only. Anyone know the solution?
P.S.: UIViewControllerBasedStatusBarAppearance = NO and UIViewControllerBasedStatusBarAppearance = NO are the same thing..
add this key to your info.plist
UIViewControllerBasedStatusBarAppearance = NO
Set
UIViewControllerBasedStatusBarAppearance = YES
in the info.plist and in each controller implement
- (BOOL)prefersStatusBarHidden {
return YES; // or NO
}
Then whenever you need a status bar appearance update (e.g. in the viewDidLoad of a controller) call setNeedsStatusBarAppearanceUpdate.
As per the documentation of setNeedsStatusBarAppearanceUpdate:
Call this method if the view controller's status bar attributes, such as hidden/unhidden status or style, change. If you call this method within an animation block, the changes are animated along with the rest of the animation block.
So for instance
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
...
}
will hide/unhide the status bar (aside from other potential style changes) whenever the view controller's view loads.
Optionally you can also animate the transition wrapping the call in an animation block
- (void)viewDidLoad {
[super viewDidLoad];
[UIView animateWithDuration:0.5 animations:^{
[self setNeedsStatusBarAppearanceUpdate];
}];
...
}

UINavigationController navigationBarHidden

Hey everbody, i'm having problem with a simple question.
I have a NavigationController, 01.xib ans 02.xib.
I set in IB NavigationController to dont display the navigationBar. Well, when i go to 02.xib, i set it to appear.
[self navigationController].navigationBarHidden = NO;
Everything works fine.
But, when i come back to 01.xib with the top button, the bar still appearing in the 01.xib.
How can i fix that?
Thanks!
Use this in first view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:animated];
}
I believe this is happening because they are referencing the same navigation controller.
You could set it hidden again in the viewDidAppear method of your 01 class.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self navigationController].navigationBarHidden = YES;
}

UIScrollView shifts below navigation and status bar

I have view which contains a scrollView. When the view shows up the image appears in full screen (320x480) hiding the status and navigation bar. When I tap the screens - status and navigation bar appears on the screen. But this thing shifts the UIScrollView below the the navigation bar. I want the status and nav bar to show over my scroll view.
Like it happens in the photos app. On tapping the image the status and nav bar shows over the scrollView.
Below is how I am positioning the view
//What I have done in viewDidLoad
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
self.wantsFullScreenLayout = YES;
scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = scrollView;
Below is what I am doing on detecting a single tap
- (void)tapDetectingImageView:(TapDetectingImageView *)view gotSingleTapAtPoint:(CGPoint)tapPoint {
// single tap hide/unhide the status and nav bar
NSLog(#"got a single tap");
if (self.navigationController.navigationBarHidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
}
Just a pointer for you guys -
If I use [self.view addSubview:scrollView]; I dont see this issue. But this mess up my landscape orientation code.
Anyone who can shed some light what I might be doing wrong - would be great help!
There appears to be some special handling inside UIScrollView when the navigation toolbars are toggled. As you pointed out at the end of your question, if you put the scroll view inside a containing UIView, this repositioning problem does not occur.
To fix the landscape issues, make sure you're setting the autoresizingMask on both the container view and the scroll view. I did not have to add any additional handling for landscape mode in my project.
I found the solution myself.
In my tap detecting code's else fn I add the below line in the last.
scrollView.contentOffset = CGPointMake(parentScrollView.contentOffset.x,0);
Not sure if this is the right approach. But if anyone can suggest a better approach - more than welcome!