'Go back' Button - xcode4.5

In Xcode, I've got one ViewController segued to a second, and on the second I've got a 'go back' button:
The initial programming was:
- (IBAction)onBackButtonPressed:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
But as of iOS 6 the code has deprecated - what should I use then?
I'm a beginner, and basically want to programme a button which takes me back to the original ViewController from my second one.

The new method you could use is:
[self dismissViewControllerAnimated:NO completion:nil];

Related

inputAccessoryView doesn't appear automatically after call "reloadInputViews"

First I subclass UIView named MyTextEditorView for overwrite it's inputAccessoryView as readwrite property.
#property (retain, readwrite) UIView *inputAccessoryView;
And I initial UIInputView as display view,then add one UIView as subview;
UIInputVIew *myInputAccessoryView = [[UIInputView alloc] initWithFrame:CGRectMake(0,0,screenWidth,44)];
[myInputAccessoryView addSubview:myDisplayView];
[self setInputAccessoryView:myInputAccessoryView];
[self reloadInputViews];
And I have overriden canBecomeFirstResponder for return YES;
- (BOOL)canBecomeFirstResponder
{
return YES;
}
When I first initial MyTextEditorView in my viewController1 and make it become first responder,then inputAccessoryView automatically appear.But when I push another viewController2 from this viewController1 and back to viewController1 ,inputAccessoryView will not automatically appear after make it become first responder.
However,when I add some code as following:
UIInputVIew *myInputAccessoryView = [[UIInputView alloc] initWithFrame:CGRectMake(0,0,screenWidth,44)];
[myInputAccessoryView addSubview:myDisplayView];
[self setInputAccessoryView:myInputAccessoryView];
[self resignFirstResponder];
[self reloadInputViews];
[self becomeFirstResponder];
After then, this inputAccessoryView can automatically appear in any case.But this confused me and anyone can help me raise why the inputAccessoryView can't appear automatically?Thanks in advance!!!
I test this question on both iOS7 and iOS8. And I find it's an iOS8 bug.After I replace UIActionSheet with UIAlertController on iOS8 platform, this works well.
I guess that UIActionSheet as subclass of UIView is different from UIAlertController as subclass of UIViewController which maybe conflicts with my editor

iOS 7 status bar overlaps camera controls on UIImagePickerController

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;
}

UINavigationCotroller backBarButtonItem with other target than self

I am trying to change the action executed by pressing the backBarButtonItem of a Navigation Controller.
I know that i have to edit the backBarButtonItem before the next view (on which the button with custom behavior should appear) is pushed. So in the previous ViewController i added the following code, to push via segue:
#pragma mark - segue methods
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"SettingsToProfile"]) {
MyProfileViewController* myprofileVC = [segue destinationViewController];
myprofileVC.myProfile = myProfile;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Settings_" style:UIBarButtonItemStylePlain target:myprofileVC action:#selector(popTOSettingsViewController:)];
} else {
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStylePlain target:nil action:nil];
}
}
The title "Settings_" gets displayed correctly, but "target: myprofileVC action:#selector(popTOSettingsViewController:)" doesn't seem to have any effect at all.
Background:
MyProfileViewController is a View, where the user can edit his/her own information. Whenever the backbarbutton is clicked, i want to check if something in the GUI has been changed by the user. If thats the case, a UIAlterView should ask the user, if he/she wants to save the changing. I tried to work it out with, viewWillDissappear, but the AlterView gets displayed in the next ViewController (and program crashes, if i click on the alterViewButtons).
I'm not sure that you can change the target of a backBarButtonItem. How about self.navigationItem.leftBarButtonItem instead? There's a discussion at self.navigationItem.backBarButtonItem not working ?? Why is the previous menu still showing as the button? that may be relevant.

Swipe gesture instead of backbarbuttonitem with UINavigationController

I've looked around and I can't for the life of me find a way to replace the backbarbuttonitem with a swipe gesture. I want to swipe left and have the app revert back to the previous view controller. Just to clarify I'm using a UINavigationController to manage all my View Controllers. Any ideas? Or is this not possible? Thanks!
I worked it out and now I feel stupid for asking this question! Here is the code I used:
I created a Swipe Gesture in the ViewDidLoad function:
- (void)viewDidLoad
{
[super viewDidLoad];
// -- EDIT Added the allocation of a UIGestureRecognizer -- //
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(gotoPreviousView:)];
swipeRight.numberOfTouchesRequired = 1;
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
}
Then I simply created this...
- (void)gotoPreviousView:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
Easy! Looked too far into it and the answer was staring me in the face. Hopefully if you don't know how, you'll see this and not make the same rookie error I did ha...

Can't push a view from a modal view in iOS5

I have a Navigation Controller based app. From my Root VC, I have one view that I present modally like this:
[self.navigationController presentModalViewController:shortcutsViewController animated:YES];
shortcutsVC contains a row of buttons, which take the user to various places in the app.
In iOS 4.3, this works:
UINavigationController *saveNavigationController = (UINavigationController *)self.parentViewController;
[saveNavigationController pushViewController:multipleListViewController animated:YES];
[saveNavigationController dismissModalViewControllerAnimated:YES];
[multipleListViewController release];
It does not work if the dismiss happens before the push.
In iOS 5, it doesn't work at all, regardless of which order the two commands are in.
By "not work" I mean that the button highlights briefly but the new VC is not displayed.
What is the right way to do this? Or am I doing something that was illegal all along and just happened to work in 4.3?
EDIT:
I got some offline help on this one.
The problem is that in iOS5, parentViewController has been renamed presentingViewController. Since I still need to support both 4.x and 5.x, I changed this
UINavigationController *saveNavigationController = (UINavigationController *)self.parentViewController;
to this
UINavigationController *saveNavigationController;
if ([self respondsToSelector:#selector(presentingViewController)]) {
saveNavigationController = (UINavigationController *)self.presentingViewController;
} else {
saveNavigationController = (UINavigationController *)self.parentViewController;
}
And all is happy now.

Resources