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..
Related
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.
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 create a camera overlay that can recognize swipe gestures to push to other views.
I am wondering if I can still use the UIImagePicker or if I have to use the AVCaptureSessionManager.
Also i would prefer to create the overlay view in the story board is there a way to do that?
can I select a view inside the storyboard controller be the camera overlay and simply present the UIImagePicker on view did load?
I've never used the Storyboard to create a camera overlay, but I have created a xib which works fine. You can create the overlay viewController in the normal (xib) way, complete with gesture recognizers, then you can handle them directly in that VC or use a delegate (most likely the VC which presented the camera).
Some code -
-(void)setupCamera
{
self.picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.overlay = [[OverlayViewController alloc] init];
_overlay.delegate = self;
_picker.cameraOverlayView = _overlay.view;
_picker.delegate = self;
[self presentViewController:self.picker animated:YES completion:nil];
}
The overlay -
-(id)init
{
self = [super initWithNibName:#"OverlayViewController" bundle:nil];
if (self)
{
// set up stuff
}
return self;
}
... & some code which handles the swipe -
-(IBAction)swipe:(UISwipeGestureRecognizer *)sender
{
// swipe stuff
[self.delegate doSwipeStuff]; // if you want the delegate to handle it
}
Hope this helps.
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´m trying to deal with activityIndicator in my iPhone app.
But it doesn´t work at all.
Inside my project I have a UISearchbar.
When people put the keyword and click the search result will show string in UIWEbview.
I really want the activity indicator show and animate while waiting for data and Stop when data is loaded.
Here is some of the code I use :
#implementation myFirstappController
#synthesize myWebview, activityIndicator;
- (void)webViewDidStartLoad:(UIWebView *)myWebview
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)myWebview
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityIndicator stopAnimating];
}
///Here is code inside the UISearchbar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *keywords = searchBar.text;
NSString *infos = [NSString stringWithFormat: #"%#", keywords];
NSString *rs=nil;
if ([infos isEqualToString:#"Iloveyou"]){
rs =#"<span style='color:#3B5998; font-size:25px;font-weight: bold;'>I love you too </span> <span style='color:#666; font-size:18px;'> -rte,-rt </span> ;
[myWebview loadHTMLString:rs baseURL:nil];
}
- (void)dealloc {
[myWebview release]; //<-------JUST FILL THIS LINE**********************
[activityIndicator release];
[searchBar release];
[super dealloc];
}
#end
In your example you're "loading" a string, which will be instantaneous, so (because the iPhone combines animations) the indicator will never animate.
You should try your code with a remote URL.