UINavigationController popToViewController appears triggered twice - ios

Can anyone explain what would cause a call to:
[self.navigationController popToViewController:self animated:YES]
To start, get half-way, then appear to restart, where the popping UIViewController jumps all the way back to the left edge, the animation begins again, and then completes?
It is as if it has been called twice, but to debug I subclassed UINavigationController and placed breakpoints in both popToViewController and popViewControllerAnimated, and only popToViewController is called once.
When I call
[self.navigationController popToViewController:self animated:NO];
It behaves exactly as expected, but obviously without the animation, which I would like to see.
Thanks!

I've seen this on questions before where people added multiple actions for something like "TouchUpInside" and "TouchDownInside".
If you're using storyboards you may want to look at what actions are connected to your buttons.
Or another possibility is doing it through storyboards and code.

I have uncovered the cause - I had an iOS toast UI library that was triggering in the middle of a navigation event that was disruption the transition.

Related

Does the method popViewControllerAnimated: act different than the Back button of the NavigationController?

In my Application i have a container ViewController which is the RootView of an UINavigationController.
I transit between various Child ViewControllers through a segmentedControl in the Toolbar of the UINavigationController.
One of the Child views pushes another View on the NavigationController, keeping the ToolbarItems.
Using the Back Button I get the desired behaviour of returning to the RootViewController, but any try of going back programatically won't change the view.
popViewControllerAnimated always takes the topViewController of the Stack but nether updates the View. viewWillAppear of the Container ViewController won't be called this way.
So i am wondering if the Back button does any additional Stuff which won't happen in with popViewControllerAnimated.
Also popViewControllerAnimated:YES will freeze the app without throwing an error.
Thanks for the help in advance.
Edit:
Ok one test case was a little of.
A popViewControllerAnimated in the topViewController of the Stack works as normal. But a call to popViewControllerAnimated through the SegmentedControll does not.
I realise the way i wrote this might be a little confusing, i will try to make this all a little clearer later.
Ok, it was a timing issue. I changed the ChildViews of the container ViewController directly after the call to popViewControllerAnimated.

Modal ViewController presenting another viewController won't animate immediately

Yes, I struggled a bit with that title...
Here's what my setup is meant to do:
I push a viewController (resultViewController) onto the navigation stack. Immediately (literally in the next line of code) I present another viewController to the rootViewController (filterViewController).
So far, so good, and things work as expected.
The modally presented viewController contains a tableView. Selecting a cell is supposed to present another viewController in the current (filterView) controller.
[self presentViewController:filterDetailsController animated:YES completion:^(void){
}];
This is where things go awry: The above snippets is called at the correct time, but the viewController does not appear until I perform an additional tap or gesture somewhere in the filterView. This suggest that the stacking of modalView inside modalView somehow messes things up. If I change the animated parameter to NO, the viewController is presented immediately.
An obvious work-around would be to set animated to NO and perform a manual animation in the completion block. I would however love to see if anyone have come across anything similar and knows how to fix the problem.

ios - what is the effect of having a UINavigationController on segueys?

I have an app that uses UIViewControllers for everything pretty much. So far I have been using push segueys when there are either button clicks, or some logic after which I have to show a new screen.
Sometimes it works and sometimes I get strange behavior where the next page loads and gets stuck, and its nav bar area does not load.
I use this code:
BusinessController *businessController = [[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"BusinessController"];
[self presentModalViewController:businessController animated:YES];
I have been reading that I should use the modal seguey possibly, but I am not sure which one is better.
Also, I have been reading that I need to embed my controller in a NavigationConroller if I want to to push, but I am not sure what effects that will have on the rest of my app.
Please help me understand what is the right approach here for me.
Thank you!
For the record....
If you're creating segues you ought to use them, either by linking them to a control so that they activate automatically or by calling performSegueWithIdentifier:sender:. (As a general statement, modal controllers are an interruption of program flow while pushed controllers are like a stack you move though back and forth.)

performSegueWithIdentifier failing presentPopoverFromBarButtonItem Popovers cannot be presented from a view which does not have a window

I have a Master/Detail view which opens a popover view via storyboard segue. There is an add button on the navigation bar of the Master view controller which works fine.
I added an editing mode where the same popover is invoked by selecting a table cell in edit mode. It fails from the [self performSegueWithIdentifier:#"addQuery" sender:self]; statement. The viewDidLoad in the popover is invoked, but after that the exception is thrown.
I am not invoking presentPopoverFromBarButtonItem - it seems to be coming from the performSegueWithIdentifier.
There is no question that the Master View Controller has a window - a table cell for that view was clicked to start the whole process that is failing.
The popover is the beginning of a navigation controller sequence, which may be part of the problem. Everything is working fine when it really is invoked by the button, just trying to programmatically invoke it is failing.
I have tried changing the "sender" for the performSegueWithIdentifier to no avail.
I suspect the problem has to do with the segue not being invoked by a button, and I do not know how to fake that out.
Any ideas?
There appear to be some bugs in how ipad popover segue's work - see Wayne Hartman's blog post
A simple test revealed that viewWillAppear is being called after viewDidLoad.
I think I understand the problem... havent' worked out the solution yet.
The order in which the methods were called are...
[initiate segue]
viewDidLoad
prepareForSegue
viewWillAppear
I moved my initialization code to the viewWillAppear method - and it worked.
In general, I feel it may be a good idea to initialize within viewWillAppear instead of viewDidLoad anyway.
I have a similar issue:
I am using UIDocumentInteractionController to open a kaynote document in Kaynote app. I was using same code:
[docController presentOpenInMenuFromBarButtonItem:_actionBarButtonItem animated:YES];
Code above was opening popover from actiobBarButtonItem with options what app I would like to use to open my file. If I same thing from DetailViewController I get same error message as author of this thread: "Popovers cannot be presented from a view which does not have a window"
And I was able to find a quick solution for my issue . I am not sure if it will be relevant to yours. Instead of using "presentOpenInMenuFromBarButtonItem" I used "presentOpenInMenuFromRect" and thats it. You just need to define right place for popover to apear

Restart drawing and events in UIViewController (iOS)

Simplified question: Is there any way to restart the navigationController of an application?. I'm trying to force the application to get his initial appearance.
Long explanation
I've a pet project in iOS and I have a weird problem with the interface that I'd like to solve. I'd like to understand also the mechanics behind this behavior.
I've a simple welcome view, wich shows the splash screen of the application. After that, thread goes to sleep state for 1.5 seconds.
[NSThread sleepForTimeInterval: 1.5];
Then, I'm showing an advertisement view:
AdController *ad = [[AdController alloc] initWithNibName:nil bundle:nil];
[self.navigationController presentModalViewController: ad animated:YES];
[ad release];
And that's all the logic behind. After that, other controllers are pushed without incidence. I want to achieve that, if at any moment the user makes the application go to background (pushing the iPhone/iPad button) then all the controllers must disappear from the stack via pop. In order to get it I'm using applicationDidBecomeActive event from the delegate. The code is the following:
[self.navigationController dismissModalViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:YES];
This is driving to some weird visual behaviours. Depending of the moment that the user choose to push de button the transition to the first view is visible. In other cases the ad view is still present, so it is dismissed and then appears the splash screen.
It will be great if there is some way to reset this first controller (splash screen), in order to get all the transitions working as the first time. I've thought about pop it from the navigation controller and the reload another one, allocating again, but it seems a bit complicated.
Is there any simple way to achieve that?
Important Edit: If the user forces repeatedly the application to go background then these exceptions are thrown:
nested pop animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
The easiest way that I've found is to add to the plist file a new row with key "Application does not run in background" and with value YES.
Forces the application to be completely closed and unloaded from memory when the user pushes the button.

Resources