Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentViewController - view solid black, viewDid___ methods not called

    ...
    SecondViewController *svc = [SecondViewController new];
    [self presentViewController:svc animated:YES completion:NULL];
}

This code is exactly the same as what I used in another app, but here I'm using presentViewController rather than presentModalViewController
(completion:NULL makes them effectively identical. Same result, at least.)

Both attempts at creating a modal view are structured the same way. Those lines in the main view, a view controller in the Storyboard, and matching .h and .m files. The only difference is that here I want a programmatic trigger, so it's impossible to drag a segue and be done with it.
I have an object set to recognize a gesture and call the transition method. That's probably what's causing the problem (part of it, at least), but it is necessary.

Using a UIButton would be cheating. No deadline, no shortcuts.

EDIT: NSLog output shows something odd.

2012-04-05 10:41:12.047 MyApp[5962:707] <SecondViewController: 0x1d8c130>
2012-04-05 10:41:12.479 MyApp[5962:707] <SecondViewController: 0x1d8e360>

So I'm doing something stupid again that happens to have a very simple fix, right?
Edit again: presentViewController… was being called more than once. Fixed it. Still black, though.


Back to performSegueWithIdentifier:sender: instead of the much easier presentViewController:animated:completion:

Terminating app due to uncaught exception 'NSInvalidArgumentException", reason: 'Receiver … has no segue with identifier …'

I told it to perform a segue, but there isn't one in the Storyboard (I can't add one, there is no Storyboard Segues section under 'Connections inspector' for the object I'm attempting to use), so it crashes. This is normal behavior.

What I want is to have a modal view without needing to create a segue. I've done it, so I know it's possible.
All I need is a bit of help getting it to work.

.

performSegueWithIdentifier:@"Identifier" sender:nil NSSInvalidArgumentException
presentViewController:viewController animated:YES completion:NULL Empty View

like image 775
Thromordyn Avatar asked Apr 05 '12 14:04

Thromordyn


2 Answers

Got it.

Replace the lines in the question with this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard"
                                                     bundle:nil];
SecondViewController *viewController =
            [storyboard instantiateViewControllerWithIdentifier:@"SecondView"];
[self presentViewController:svc animated:YES completion:NULL];

Credit for this solution goes to IturPablo's self-answered question:
TabBarController, overwriting shouldSelectViewController to do a segue

like image 119
Thromordyn Avatar answered Nov 17 '22 19:11

Thromordyn


Are you looking for performSegueWithIdentifier:sender:? The docs seem to match your description:

"you can call this method to trigger a segue programmatically, perhaps in response to some action that cannot be specified in the storyboard resource file"

like image 35
Phillip Mills Avatar answered Nov 17 '22 19:11

Phillip Mills