iOS Navigation Controller Back Button Causing Glitch - iphone

I have a navigation view that contains a tableview. If one of the tableview items is clicked, the navigation controller passes the user to the detail view.
This usually works perfectly. However, if the user clicks the back button from the detail view and moves back and forth between the tableview and detail view too quickly, the app will sometimes become glitchy.
This glitch occurs rarely, but when it does, the back button makes the view transition to the left, but it just shows the detail view again. Then I need to press the back button again in order to actually go back to the list view.
Does anyone know why this might be happening? Or is there a bit of code I can post to help resolve this? Thanks!

Try this:
//in viewwillappear
appDelegate.window.userInteractionEnabled = FALSE;
[self performSelector:#selector(userInteraction) withObject:nil afterDelay:0.5];
-(void)userInteraction
{
appDelegate.window.userInteractionEnabled = TRUE;
}

Related

stop view from disappearing

I am launching a viewController from another view controller via the push on its table views cell. Now on the second view controller I have a whole bunch of controls mainly test fields. I would like to by using the default back button provided in the second view controller so it'll be the title of the first view controller and keep in mind like I said default, so I don't want to create my own button for back on the second view controller. So would like to detect if the second view controller is exiting or disappearing or will disappear and based on certain conditions stop it from going back to the original caller view controller. I originally assumed it could be done in here:
-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound)
{
// So back button was pressed on the second view controller, so how do I stop it
// here from going back to the original view controller.
}
}
Or how do I do it? I can't seem to find a view controller return type BOOL method to call and stop it.
Thanks.
Note that method is called viewWillDisappear, not viewShouldDisappear, so Apple won't let you stop the view from disappearing at that point. And from the user's point of view, pressing the back button should indeed take them back. Instead you might consider hiding the back button under the circumstances where it's not allowed.
You can't prevent the view controller from closing however you can emulate it.
This line will replace the close button with a button that will call a homemade function
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(closeBtn)];
So you will be able to close the view if you want:
- (void) closeBtn
{
bool shouldClose=true;
// Your conditions here
if (shouldClose) [self dismissViewControllerAnimated:YES completion:nil];
}
sorry,i'm not good at english,so reading so long text is a little difficult for me.i can only get that you want to go back without a button. i known navigationController has a method to go back to previous view.
Make a custom back button and use self.navigationItem.hidesBackButton=YES
Add target to your custom back button and use it as you like. When you want to move the view you can use [self.navigationController popViewcontroller].

View is blank after modalViewController is dismissed

I am using PPRevealSideViewController and I am showing a ViewController modally after user taps a cell in a side view. When I dismiss a modal view controller, the view, where user tapped, is shown blank. Only after I move a little bit side view, it is shown again (refreshed). What might be the problem?
This was a side effect of your preload call on viewWillAppear or DidAppear in fact. The view should not be preloaded if shown. I added this behavior as default into the controller.
But the idea behind was to test if [self.revealSideController sideDirectionOpened] != PPRevealSideDirection from the side you are trying to preload.
Fixed right here https://github.com/ipup/PPRevealSideViewController/commit/a1ca242422f0a8b4666df5987ca4a020f869bb99

Present ViewController without Back button

I'm having an annoying problem which takes the best off me :<
I've got 3 view controllers, one to show an advertisement in detail which also has a toolbar. Now what I want is, if the user presses the facebook icon on my toolbar in the first view it has to perform a check. If the check turns out false it needs to go to a 2nd view which shows a login screen. If the user logs in here it has to go to a 3rd screen which shows a simple input + button to update their status.
When the user is at this third screen there should be a button "Back", but this button shouldn't bring them back to View2 but it should bring them back to View1 (the advertisement detail screen).
I figured that I wanted to show the 2nd screen (if check turns false) without pushing it but keeping the NavigationBar + TabBar presented. I added some screenshots to clarify.
First view
Second view
I want this view to be presented without using PushViewController but keep the NavigationBar and TabBar.
Third View
I hope this is enough information, hopefully someone can help me.
Thanks in advance!
Perhaps the most natural thing to do here is to present the login view controller modally. When the user has logged in successfully, the first controller can then push the third view controller onto the navigation stack. This way, the back button will lead directly back to the first view controller, and the user will understand why.
So if we have three UIVIewControllers:
DetailViewController
FacebookLoginViewController
UpdateViewController
We have two viable options:
1) Upon successful login...pop the current LoginViewController and then push the UpdateViewController
PopViewController(detailViewController, false);
PushViewController(updateViewController, true);
2) Present the login Modally and simply present the UpdateViewController
PushModalViewController(loginViewController, true);
//ascertain result of login
if(IsLoggedIn) {
PushViewController(updateViewController, true);
}
consider the following view push logic.
if (!login) {
LoginViewController *lvc = [[[LoginViewController alloc] init] autorelease];
[self.navigationController pushViewController:lvc];
}
else {
ThirdViewController *tvc = [[[ThirdViewController alloc] init] autorelease];
[self.navigationController pushViewController:tvc];
}
It is : create and push the view controller when it is needed.
Try to pop the current view controller (without animation i guess) before pushing the new one. If there is only one view controller in the navigation stack no back button will be shown.
Haven't used Monotouch but i guess something like this:
this.NavigationController.PopViewControllerAnimated(false);
this.NavigationController.PushViewController(newViewController, true);
But as Caleb suggests it's probably better figure out a way that fits the normal navigation behaviours instead of hacking around it.

black bar as the view fades when I am using navigation controller

I'm writing my first iPhone app and I am trying to figure out how to have a MasterView and DetailsView like in the example. However, instead of using a TableView, I want to use a button on the MasterView to go to the SignUpView. I want the MasterView to NOT have a navigation bar but the SignUpView needs to have one.
I have tried putting a NavigationController into the MasterView using the interface builder. This doesn't seem to do anything at all ... I.e. I make the following call:
[self.navigationController pushViewController:signUpViewController animated:YES];
And nothing happens. The SignUpView is never shown.
So then I declared a NavigationController in the AppDelegate. The above call in the same function that it was in before (button handler, button is in MasterView) works now! It takes me to the SignUpViewController.
however, the issue is, when I press back on the navigation bar in the sign up view, the navigation bar shows up again in the MasterView. I tried to set
self.navigationController.navigationBarHidden = YES;
in viewDidLoad and viewDidAppear, but that causes a black bar to appear in the transition from SignUpView to MasterView.
I tried to not set it in one of the two, and that causes the animation to go smoothly, but the navigation bar shows up in the MasterView.
I feel like this should be pretty simple to do ... but I'm at my wits end trying to figure this out. Some help would be really appreciated!
Thanks.
Probably not the answer to your question, but just a small suggestion. In the many apps that I have come across, a sign-up/sign-in view is generally displayed as a modal view (on top of your master view) with a 'cross' in the top-right corner to dismiss it. Probably it results in a better user experience.
Also, did you try self.navigationController.navigationBarHidden = YES; in the MasterView's viewWillAppear ?
HTH,
Akshay
I had this problem too, until I discovered setNavigationBarHidden. You will probably want to use these in viewWillAppear/viewWillDisappear or viewDidAppear/viewDidDisappear. You don't want to call this in viewDidLoad because that is only called once when the view is initialized, not every time it appears.
To hide:
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show:
[self.navigationController setNavigationBarHidden:NO animated:YES];

UINavigationController doesn't fully push view and only changes the Navigation toolbar to the next view's toolbar

So I have an iPhone application that utilizes a UINavigationController for setting up the views. When the application first starts, it presents the user with a UITableViewController and the user can select an item and it will push another view. Now I have it set so that my app remembers the user's last selection and automatically selects it and loads the correct view controller. The only problem is that I am experiencing a really weird glitch when I load the next view automatically..
When the view is pushed, the navigation toolbar will change so that a back button directed to the previous view is showing but it won't display the next view. It will instead keep showing the table view and I can interact with it as well. I can press the back button and it will change the toolbar back and the tableview is still shown. Then when I select an item it loads the view just fine.
Thanks for the help.
Code:
I determining whether to push the view controller based on whether it can connect to a server. I do this in a backround thread:
- (void)startingThread
{
[NSThread detachNewThreadSelector:#selector(loginThread:) toTarget:self withObject:communicator];
}
- (void)loginThread:(MowerCommunicator *)communicator
{
//If it can connect, launch thread complete.
[self performSelectorOnMainThread:#selector(loginThreadComplete:) withObject:communicator waitUntilDone:NO];
}
- (void)loginThreadComplete:(MowerCommunicator *)communicator
{
//push view controller
}
Now I have added NSLog statements to track if the view is actually "showing" and both viewWillAppear and viewDidAppear get called. I also check the delegate methods for the navigation controller and they get called as well.
I have a view that is the initial startup view and it reads from a server to determine what to display in the next table view. That gets pushed fine and when the tableview gets pushed, I hide the back button so the user can't get back to the first view without closing the app. Then the tableview looks at a variable in NSUserDefaults to determine with there is a saved index and then pushes the next view controller. That is when the glitch occurs. If I then press the back button to "go back" to the table view (this really just changes the navigation toolbar) and then I select an item from the table view, it loads the next view correctly. Also, I call the exact same methods when the user pressed an item from the table view and when the app loads the view automatically.
The simplest explanation is that you're pushing the initial tableviewcontroller onto the navigation controller's stack twice.
If you have the initial tableviewcontroller set as the nav's first controller in a nib but then you push the same controller onto the stack when trying to automatically display the stacked views, you would get what you are describing. The nav starts out with the controller from the nib and then you push another instance on top of that.
You should log the nav's viewControllers property before and after you do the automatic push to see what the actual state of the stack.