In my app I don't show the status bar.
In IOS 7 I had to add "View controller-based status bar appearance" to the info plist, which is fine, but when I use the following code:
imagePicker.allowsEditing = YES;
imagePicker.sourceType = (sender == self.chooseImageBtn && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
The status bar is shown again, even though I add the following code:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
This problem comes when you open the imagepicker because the status bar is shown forcfully there.
I faced the same problem.
Here is my solution. put this in the viewWillAppear of the view controller from which you are opening the image pickerview
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
I fought with this for a long time as well. This is what finally got rid of it for me.
- (void) navigationController:(UINavigationController *) navigationController willShowViewController:(UIViewController *) viewController animated:(BOOL)animated
{
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[self setNeedsStatusBarAppearanceUpdate];
viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size;
}
}
Also, in your Info.plist, add:
View controller-based status bar appearance: NO
Hope that helps.
Related
I've tried setting the Info.plist 'View controller-based status bar appearance' to NO, I've tried calling
[[UIApplication sharedApplication] setStatusBarHidden:YES];
I've tried
-(BOOL)prefersStatusBarHidden{
return YES;
}
I've tried launching the picker with
[self presentViewController:picker animated:NO completion:^{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
And still, there is a status bar overlapping the camera controls. It's only there in iOS 7 though.
The status bar doesn't show up any where else in the app. I feel like I'm missing an important piece of the puzzle here, and no amount of reading about the View Controller or UIImagePickerController has helped me find said puzzle piece.
I'm hoping some one else has a little insight into this problem. Thank you.
EDIT: My desired effect is that the Status Bar shows up every in the app, except on the camera picker and a few other "outside" (Email related) view controllers we use.
If you want to keep ViewController-Based Status Bar Appearance, subclass UIImagePickerController and override prefersStatusBarHidden and childViewControllerForStatusBarHidden.
#interface NoStatusBarImagePickerController : UIImagePickerController
#end
#implementation NoStatusBarImagePickerController
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (UIViewController *)childViewControllerForStatusBarHidden {
return nil;
}
#end
Try this :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
in your appDelegate.
There's an additional setting you need to turn on, starting in iOS 7. In your app's Info.plist, add a line for View controller-based status bar appearance, a Boolean, and set it to NO.
The PsychoDad method works for me. I put the following
[[UIApplication sharedApplication] setStatusBarHidden:YES];
into the method viewWillDisappear of subclass of UIImagePickerController.
But the Alexandru Dranca method is better because in that way the status bar don't appear at all!
However I think this is a BUG of IOS 7...
"View controller-based status bar appearance" set to NO, works for me.
you should leave the
-(BOOL)prefersStatusBarHidden{
return YES;
}
and also add this
-(void)viewWillAppear:(BOOL)animated {
...
[self setNeedsStatusBarAppearanceUpdate];
...
}
I've been on this bug for repairing ToonPAINT for iOS7 and the thing that finally worked other than setting the two things in the Info.plist file (Status bar is initially hidden = NO; View controller-based status bar appearance = NO)
was to change the style of the status bar (even though I didn't want it shown at all); It was not enough to just hide the status bar; sounds like an iOS7 bug.
In the app delegate add:
-(void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
{NB .. UIStatusBarStyleBlackTranslucent is deprecated, probably use UIStatusBarStyleLightContent if trying this}
I think the answer to this question is "This is an iOS 7 bug". None of the methods here helped in our case, and several people have tried to fix this now.
I can't say what steps to reproduce this, but I've seen enough people out there with the same issue, that I think it's safe to say that this is in fact an iOS 7 bug. Most people can fix this problem with the multiple methods listed above. Rarely though, you can't fix it that way. I hope if you are reading this, you are not also one of those people.
This is what worked for me:
#implementation ViewController {
BOOL hideStatusBar;
}
- (void)showCamera {
UIImagePickerController *camera = [[UIImagePickerController alloc] init];
camera.modalPresentationStyle = UIModalPresentationCurrentContext;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.delegate = self;
hideStatusBar = YES;
[self setNeedsStatusBarAppearanceUpdate];
[self presentViewController:camera animated:YES completion:nil];
}
-(BOOL)prefersStatusBarHidden{
return hideStatusBar;
}
I am trying to build a view where a user can select an image and it is retained within that view after navigating away from the view and coming back again. As a simple test app, I have created two view controllers. The first view controller has a forward button and uses a modal segue to go to the second view controller. The second view controller has a back button (modal segue back to first view controller) a Choose button and a Image button. So far I have configured the choose button to use the imagepickercontroller to select an image from the library and display onto the button which works no problem. The issue is that when i press the back button and the forward again back to the same screen the image isn't retained i have to reselect it. The intention is for the user to be able to take a picture or video of themselves performing an action and then select it within this app and have the picture displayed there for future reference.
My coding is as follows:
ViewController.h
#interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
IBOutlet UIButton *selectFromPhotoLibraryButton;
IBOutlet UIButton *displayPictureButton;
}
#property (nonatomic, retain) UIButton *selectFromPhotoLibraryButton;
#property (nonatomic, retain) UIButton *displayPictureButton;
- (IBAction)selectPicture;
#end
ViewController.m
#implementation ViewController
#synthesize selectFromPhotoLibraryButton;
#synthesize displayPictureButton;
-(IBAction)selectPicture
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
[displayPictureButton setImage:image forState:UIControlStateNormal];
[self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Please let me know if you require any of the other bits of code (its only the default app stuff, no further modification).
As looking to your problem
I think you have to store selected image in NSUserDefault as archived data or something like that.
When u come back to second view then check first in NSUserDefault for image is saved or not.
If u got it then assign it to UIImage object by unarchiving.
As I have not implemented it so can't be sure.
I've just set something like this up myself, I have the chosen image immediately placed in a UIImageView.
First, set up your view controller as a UIImagePickerDelegate:
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
Then wherever you want to init the UIImagePicker, alloc, init and set its delegate to self:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
And then I have the image picker storing the UIImage into the ImageView and also into the NSUserDefaults.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
UIImage *image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
[userDefaults setObject:image forKey:#"image"];
[userDefaults synchronize];
[self dismissViewControllerAnimated:YES completion:^{
[self updatePreviewImage:image];
}];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *) picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
I hope this works for you, and anyone else that view this post.
i built an app on ios 4.3 and it worked fine but when i run it on the new ios the back buttons dont work. Heres my code to go to the next xib:
-(IBAction)Selection3Page:(id)sender;{
//show next view
Selection3Page * nvc = [[Selection3Page alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:nvc animated:NO];
[nvc release];
}
and this is the code to return back to the first xib:
-(IBAction)done:(id)sender{
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
please help!!
The API for dismissing modal views was changed somewhat in iOS 5. Try this instead:
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
NSLog(#"didTouchDoneButton 5.x");
[self dismissViewControllerAnimated:YES completion:nil];
}
else
{
NSLog(#"didTouchDoneButton 4.x");
[self dismissModalViewControllerAnimated:YES];
}
post some NSLogs in there somewhere and check if the methods are actually getting called... I would start around that..
I am using core-plot sdk and trying to plot a bar chart.
I have RootViewController which extends from UINavigationController, and I am adding my viewController which render the barChart, here is code
RootViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
barChartViewController = [[BarChartViewController alloc]init];
[self pushViewController:barChartViewController animated:NO];
}
BarChartViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title =#"BarChart";
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.4 green: 0.8 blue:0 alpha:1];
self.navigationItem.title = #"BarChart";
// and then creating the barchart and rendering it, which works fine.
}
Here the navigationBar doesn't appear and so is the title for navigationBar.
And then the following code from BarChartViewController.m
-(void)barPlot:(CPBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index{
NSLog(#"barWasSelectedAtRecordIndex %d", index);
DetailViewController *detailViewController =
[[DetailViewController alloc]initWithNibName:#"DetailViewController" bundle:
[NSBundle mainBundle]];
[self.navigationController pushViewController: detailViewController animated:YES];
}
So in the above code what I am trying to do is once user selects a bar from the barChart (which is getting displayed properly), the above method gets invoked, i do see on the console the log message is getting displayed telling which barChart was selected, but the controller is not going to DetailViewController, which I am pushing here.
So as you can see I am facing two problems with the code one the navigation bar is not appearing and another one I am not able to push a new viewController to navigationController. I am guessing there is some issue with the core-plot and navigation controller.
Please help.
Thanks,
Yogesh
I have a UITabBarController whose tabs are UINavigationController. I have initialized each navigationController by:
iPhoneApp *appDelegate = (iPhoneApp *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController2 initWithRootViewController:countryController];
I then drill down the navigationController with:
[self.navigationController pushViewController:myViewController animated:YES];
I want to pop to the root of my navigationController(s) when the user clicks on a tabBar tab.
[delegate.navigationController2 popToRootViewControllerAnimated:NO];
This seems to work great when I only pushViewController one level, but fails when I drill down multiple levels in my navigationController. What happens is that it pops to root but doesn't contain my Root's backbutton or title:
self.navigationItem.title = #"My title";
self.navigationItem.hidesBackButton = YES;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleDone
target:self
action:#selector(handleBack:)];
if I don't poptoroot and just use the navigationControlls back button, everything works correctly.
I logged my viewControllers before and after i poptoroot
before:
MainCountryController: 0x3d53650,
IndividualCountryMfgViewController: 0x3d67d50,
IndividualCountryProductViewController: 0x3d60870
after:
MainCountryController: 0x3d53650
it's the right view, but wrong toolbar title and backbutton.
Anyone have any ideas? Thanks for your help.
I got this working by disconnecting my navigation controllers from IB an just creating them programatically.