I need to open a popover from a subview inside a ModalView. These subviews are added on ModalView at viewDidLoad using [self.storyboard instatiateViewControllerWithIdentifier:identifier]
When I click to open a popover the application exit without any information about the crash.
the sample project with this error can be downloaded here (https://www.dropbox.com/s/mjpaqk6xwt86dbd/PopoverTest.zip)
I´m using xCode 4.3.1 and iOS SDK 5.0 and storybord.
thanks
André
In viewDidLoad, you're instantiating a bunch of view controllers with instantiateViewControllerWithIdentifier:, but those aren't retained or referenced anywhere after that. I'm pretty sure ARC is releasing them for you at the end of viewDidLoad, which is causing the crash. If it didn't do this, it would be a leak.
One solution would be to store those view controllers in an array, and release it on viewDidUnload.
Related
I've got a segue that opens a viewcontroller via a storyboard reference in the viewDidLoad of the parent controller. Everything worked in the earlier versions of iOS and Xcode, however it seems to give me a crash now with the message
[Assert] Assuming bar button item's view exists.
I'm not sure what to do - I've tracked the crash down to the line which references the segue that opens the referenced viewcontroller.
I've set the anchor as the bar button item.
[self performSegueWithIdentifier:#"menuPopSegue" sender:nil];
Make sure you have set the identifier in storyboard which you are calling here.
I moved my code into the viewDidAppear method instead of the viewDidLoad (where it originally was). It now works and presents the viewController in a popOver - I assume the problem was because in the viewDidLoad items were initialised but not actually presented yet on screen and the new UIPopoverPresentationController class requires the anchor and its properties to be fully loaded.
I have a older iOS app that I am working on a update for. Compiling with 8.2 and 8.3 SDK I get unwanted pops to the root view controller, running on 8.3 or 7.1 iOS. Depending on the specific view configuration when I add the 2nd view to the stack I will get a instant, after viewDidAppear, pop to the rootViewController from the 2nd view or 3rd view on the stack. I have breakpointed all my popTo statements and non of them are causing it. I am getting no indication of the cause. Are there any debug tools that can help me find this?
You can subclass the navigation controller and override the popToRootViewController method with an implementation that just calls super. Put a breakpoint in there and you should be able to pinpoint the cause. (Make sure you replace the default navigation controller with the subclass).
If popToRootViewController still does not get called, the other view controllers might be getting deallocated or dismissed for some reason.
UIPopoverController *popCtrl = [[UIPopoverController alloc] initWithContentViewController:self.rootViewController.navigationController];
popCtrl.delegate = self;
[popCtrl presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
This code is in a button action, where the button is the "sender".
The line with presentPopoverFromBarButtonItem causes an exception to be thrown with the reason: Application tried to present modally an active controller DetailViewController: 0x15a54c00. DetailViewController is "self" in this case and it is only a delegate to popCtrl, so I don't see how it could be trying to present modally. It's supposed to be presenting rootViewController.navigationController.
As you may have guessed from the names, rootViewController and detailViewController are inside a SplitViewController, but prior to trying to present rootViewController with the the popover, it is removed from the SplitViewController.
This only happens on iOS 8 when built with the iOS 8 SDK. It's also not 100% reproducible. Most of the time this exception occurs, but sometimes after I restart the app it does not occur at all until I rerun the app, then it starts happening all the time again. (I put it in a try/catch so I know it can occur more than once per run.)
I'm almost positive this is yet another iOS 8 bug in the SDK, but has anyone come up with a workaround?
I faced the same problems while updating some app, which was initially developed at the times of iOS 5.0. Removing the controller from the UISplitViewController right before using it in the popover did not work, neither did it help to switch to the newer UIPopoverPresentationController.
However, I was able to swipe-in my (master) controller from the left side. More or less, I discovered that "feature" by accident, so I looked up where this came from and found this in Apple's iOS SDK 5.1 release notes:
In 5.1 the UISplitViewController class adopts the sliding presentation style when presenting the left view (previously only seen in Mail). This style is used when presentation is initiated either by the existing bar button item provided by the delegate methods or by a swipe gesture within the right view. No additional API adoption is required to obtain this behavior, and all existing API, including that of the UIPopoverController instance provided by the delegate, will continue to work as before. If the gesture cannot be supported in your app, set the presentsWithGesture property of your split view controller to NO to disable the gesture. However, disabling the gesture is discouraged because its use preserves a consistent user experience across all applications.
(Source: iOS 5.1 Release Notes, requires Apple Developer Login)
I didn't test what happens if you set the mentioned property to NO and if it releases the controller, but I wouldn't put too much hope on that.
So even after removing it manually from the UISplitViewController, my view controller was still active on that hidden swipeable pane, which appears to happen internally in the SDK. I'm aware of the fact that this still worked fine until iOS 7.x, but I actually consider that as tolerated bug now, closed with iOS 8.0.
I ended up abandoning the popover completely and using the default UISplitViewController behaviour of iOS 5.1 and above. For some extra tweaking, you can change UISplitViewController.preferredDisplayMode to fit your needs, this saved me a lot of time to upgrade old code which never heard of auto layout.
I am using a popover in iOS 8 programmatically in an IBAction. I don't know if this is a bug or not but I do know that they did make some changes to modal views and presentations. There is a good WWDC video on it, see if you can find it. The way I am doing it (keep in mind this is Swift, so you will need to do a little bit of translation) is the following:
let controller = self.settingsVC
controller.preferredContentSize = CGSizeMake(345, 234)
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
var settingsPopController = controller.popoverPresentationController
settingsPopController?.delegate = self
settingsPopController?.sourceView = self.view
settingsPopController?.sourceRect = sender.frame
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
self.presentViewController(controller, animated: true, completion: nil)
In this code, self.settingsVC is a property of the ViewController I set which is initialized to another ViewController in the storyboard, but you can replace controller with the ViewController you need to present as a popover. Also, please note that your UIViewController class must implement UIPopoverPresentationControllerDelegate.
If you need any help with the translation, I'd be happy to give you a hand.
So I am trying to get from one viewcontroller to another using the push segue (selected in the storyboard). When I arrive at the second viewcontroller, the viewDidLoad is not firing! Is that a bug or am I doing everything wrong?
It really hard to give suggestion to this kind of question,
Double check below things once.
Is Storyboard View-controller has the Class as the SecondViewController.h
Is the 'View' connected to the outlet as the Seccndviewcontrooler's View.
Performing segue are you sure pushing the SecondViewcontroller only.
Clean build the proj once.
just run the app - Place a NSLog Statment in right after the [super viewDidLoad] and see is that printing logs in console.
try keeping a breakpoint or NSLog at viewWillAppear/viewdidAppear.
What do you mean by pushed to new view? ViewControllers can be pushed not View. ViewDidLoad will be fired only when a ViewController is loaded into the memory. It can also be fired if the VC was unloaded by iOS runtime and is being loaded again.
But thumb rule is that it will fire only when the VC is being loaded not afterwards. Please elaborate your question further if I am interpreting you incorrectly.
I implemented FlurryAds on my iOS app, and created an Interstitial/Full-screen ad. Requesting and showing the ad works fine, but after I close the ad, all of my ViewController elements that were inside the .xib file become invisible. I know they are still there because if I tap on the screen the buttons that were there still respond.
Any ideas on how to solve this?
Edit: Forgot to post more information, I'm using XCode 4.5.2, my project is using ARC, no Storyboard, and the Flurry SDK is 4.0.6
This bug arises when you enter the viewController using
"[self presentModalViewController: viewController animated:YES]"
Try to use this
"[self.navigationController pushViewController: viewController animated:YES]"
Hope this will help you
:)
Ok, I finally figured out the problem and it was because of my misunderstanding how view controllers work.
All my view controllers inherited from a custom view controller, which had a full background image being added on viewDidLoad, which then faded out. All I had to do was separate adding the full background image on viewDidLoad, but having the fade out animation inside the viewDidAppear method.