"Popovers cannot be presented from a view which does not have a window" After Upgrade Xcode - uipopovercontroller

I have a project using Xcode4.3, but then I upgrade Xcode to 4.4.1, and the errors came out. My app does not have any error, and now I have some errors at runtime.
The first of them is "Popovers cannot be presented from a view which does not have a window"
I have a MainViewController, and this ViewController calls another ViewController, with a Popover. When I want to turn back to my MainViewController, my app crashes. This is my code:
-(void)clearAnimated:(BOOL)animated{
if(self.popover &&self.popover.popoverVisible){
[self.popover dismissPopoverAnimated:animated];
}
}
So, after some research, I've found the solution was this:
-(void)clearAnimated:(BOOL)animated{
if(self.popover &&self.popover.popoverVisible){
if (self.view.window != nil)
[self.popover dismissPopoverAnimated:animated];
}
}
And kind of works, because now my app doesn't crash, but now in MainViewController, the place where the popover was, it is like a shadow, like the popover is still there.
Then, when I try to go to my SecondViewController, the error appears...
How can dismiss popover?

Related

Back button on iOS app not working properly after using popViewControllerAnimated

I've created an app using storyboard. I have few view controllers with navigation controllers. Now in the last of them I have a button, which is opening instagram login view controller (I'm using this library: https://github.com/OceanLabs/InstagramImagePicker-iOS ).
Here's a piece of code:
let loginVC = OLInstagramLoginWebViewController()
loginVC.redirectURI = GlobalConstants.instagramRedirectId
self.instagramLoginViewController = loginVC
self.instagramLoginViewController!.delegate = self
self.navigationController!.pushViewController(loginVC, animated: true)
Then it shows login view controller, I can type in user/password and finally it calls delegate that user was logged in, where I do this:
if(self.instagramLoginViewController != nil){
self.navigationController!.popViewControllerAnimated(false)
self.instagramLoginViewController = nil
}
And it actually pops login view controller, however something strange things are happening from now.
When previous view controller shows up (yes I have it on the storyboard as well as the others) back button doesn't work as it should. On the navigation bar things are changing, but the rest of the screen is not changing until it reaches the very first view controller.
I've checked code inside login view controller from that instagram library and removed that line:
[self.navigationItem setHidesBackButton:YES];
So the back button appears in login view controller too and when I click it everything work. So my conclusion is popViewControllerAnimated is the one, which cause the problem.
How should I fix that?
Damn, I don't know why, but I've changed
self.navigationController!.popViewControllerAnimated(false)
to
self.navigationController!.popViewControllerAnimated(true)
And now it works.. Strange.. I wanted to do it without an animation, but well..

Two Modal VC are displayed simultaneously ios

For some reason, when I try to open a view controller via modal segue, it opens up two of the same type. Why is this happening?
Warning: Attempt to present <ModalViewController: 0x7fa062c5edd0>
on <HomeViewController: 0x7fa062e16e40> which is already presenting
<ModalViewController: 0x7fa062fb9780>
This is causing problems because I try to use delegates, but my main view controller never gets the correct delegate.
The issue occurs when I click the the button which triggers showModalView
HomeViewController
- (IBAction)showModalView:(UIButton *)sender {
ModalViewController *modalView = [[ModalViewController alloc] init];
[self presentViewController:modalView animated:YES completion:nil];
}
I tried this solution here and here and a dozen other ones, but none seem to work for me.
Why is this happening?
The problem you're having, is because you've connected a segue to the button, and are also presenting the controller in code; you should be doing one or the other. When you removed the segue, you got a black screen because you're using alloc init to create your controller. If you made the controller in a storyboard, then you should use instantiateViewControllerWithIdentifier: instead.
However, the easier way would be to leave the segue connected to the button, and delete the code you have in the button's action method. The button doesn't need an action method, if you have it hooked directly to a segue. All of this is covered in Apple's document, "View Controller Programming Guide for iOS". You should read it.

popToRootViewControllerAnimated doesn't set the prompt properly

I have a simple scenario :
a UINavigationController with several embed UITableViewControllers.
Each UITableViewController has a prompt set, except for the ROOT UITableViewController (no prompt).
And in each UITableViewController, there is a UIBarButtonItem to go back to the ROOT UITableViewController:
- (void) backHome {
[[self navigationController] popToRootViewControllerAnimated: YES];
}
It actually goes back to the ROOT UITableViewController, but it keep the prompt from the last UITableViewController, while it suppose to remove it ( knowing that the ROOT UITableViewController doesn't have a prompt).
But when I use and hit several time a custom UIBarButtonItem with the code :
- (void) back {
[[self navigationController] popViewControllerAnimated: YES];
}
it remove the prompt as expected.
Why popToRootViewControllerAnimated doesn't remove the prompt ? Especially in iOS 8.x. Because it's working in iOS 7.1.2
I use the latest Base SDK 8.1
try calling the property on the stack
[self.navigationController popToRootViewControllerAnimated: YES];
I have a similar issue and can confirm that it still exists with current Xcode & Simulator. I have a prompt on all View Controllers in the Navigation Controller except for the last one.
Popping to root without animation works for me and shows the prompt again, which otherwise wouldn't show.

Crash after a popToRootViewControllerAnimated

I have a crash when trying to switch to another VC.
Here is the structure:
TabBarController [Home, Tab2, Result tab]
from these tabs, I can push a new viewController called addVC which contains a UITextField.
What I want to do, is to be able to follow this sequence:
Tab2/Home (step1) => addVC (step2) => Result tab (step3)
To do this, I use this code in addVC :
[self.navigationController popToRootViewControllerAnimated:NO];
UITabBarController *tabbarController = ((UITabBarController*)appDelegate.window.rootViewController);
[tabbarController setSelectedIndex:2];
It works most of the time, but if the focus was in the textfield when I pop then push the result tab, the tab from the step1 is no longer accessible without a crash.
The crash log is:
[addVC respondsToSelector:]: message sent to deallocated instance 0x10977e60
NSZombie tells me that [UITextField canBecomeFirstResponder] has been called, causing the crash.
Since I use a storyboard, nothing except this is done programmatically. I guess my way to go to step3 is not the right one.
I'm using ARC and I'm not releasing anything by myself.
Any ideas?
Thanks in advance.
For those who could have the same problem, the solution was to use this:
[self.view endEditing:YES];
Before popping anything, else the keyboard is still displayed and that's what causes the crash.

Splash Page for Master-Detail Controller Crash EXC_BREAKPOINT (code=EXCI386_BPT, subcode=0x0)

(Xcode6 beta3, Swift, iPad, iOS7.1 build)
I am trying to add a splash page before a split view controller.
Added new splash page view controller in storyboard
Set Initial view by drag n' dropping arrow to new VC
Wired button to segue to the master-detail view.
I am getting the following crash: `Thread 1: EXC_BREAKPOINT (Code=EXCI386_BPT, subcode=0x0)'
Where did I go wrong? Supporting screen shots below. Note that in "Crashes" storyboard, the button segues to the Split View Controller. Thx. :)
CRASHES:
WORKS:
I have a scenario similar to your "crashing" version, but without the segue from the splash to the main view controller.
In the viewDidLoad I make my initializations, then I use this snippet of objective-c code to launch the main view controller:
UINavigationController *dashboard = [self.storyboard instantiateViewControllerWithIdentifier:#"DashboardNavigationViewController"];
[self presentViewController:dashboard animated:YES completion:^{
[[[[UIApplication sharedApplication] delegate] window] setRootViewController:dashboard];
}];
What I think it's missing in your case is changing the root view controller once it is loaded and shown. Of course if the user has to click a button to close the splash, add that code to its click handler.
If you know objective-c, you should be able to translate that snippet in swift - let me know otherwise and I'll post it here.
I hope that's the reason of your crash.

Resources