Crash when trying to open a viewcontroller via storyboard reference - ios

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.

Related

ios switch rootviewcontroller leading to crash which is caused by UIViewController over release

I setup my scene in storyboard as follow, and set it as window.rootViewController:
It's a tabbar controller, each tab view controller is embeded in navigation controller
Everything works fine, but when I add a switch button in order to set the window's rootviewcontroller to anther storyboard, the problems comes.
When I set the window.rootViewController to anther storyboard, the original rootViewController (the UITabbarController) gets dealloc. This is what I expect, but the second tab view controller gets release twice, and lead to crash.
I use zombine instrument to analyze the reference count change as follow, almost all ref count is handled by UIKIt Library, I cannot figure out where goes wrong by me, is there any hint?
BDBookingViewController is the controller of second tab, and the following is the reference counting of it
Here is the call stack of the last line in above picture
More call stack:
By the way, when I delete the dealloc function in BDBookingViewController, everything works fine. I just remove kvo there, I don't know the root reason
- (void) dealloc
{
if ([self observationInfo]) {
[[LoginManager sharedManager] removeObserver:self forKeyPath:NSStringFromSelector(#selector(isLogin)) context:BDBookingViewControllerContext];
}
}

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.

ViewDidLoad wont fire after pushed to new viewcontroller

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.

Unresponsive view instantiated with instantiateViewControllerWithIdentifier:

Im having some trouble with a view that I needed instantiating from a storyboard ID. In IOS simulator, the view loads with everything in place but is completely unresponsive. The date picker doesn't move and the buttons don't accept any interaction.
Ive checked the 'custom class' matches in IB and the Storyboard ID matches. The code is being executed in the PickerViewController because the UIDatePicker is being created in code and is correct and present in IOS simulator. Its just that nothing accepts any interaction. The buttons don't even go blue when touched.
I created the view in the previous view controller with:
PickerViewController *addViewController = (PickerViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"view"];
[addViewController.view setUserInteractionEnabled:TRUE];//chucked this line in to see if it helped
[addViewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:addViewController animated:YES completion:NULL];
I'm not sure if this is a code problem, or if I've not hooked something up in IB properly. Any ideas??!!
Check your view controllers class in assistant editor:

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

Resources