3

I am developing an application that loads a web page (using UIWebView) using Storyboard (I do know nothing about previous xib neither). I have already created a view controller for that UIWebView and everything works fine. The thing is: since previous versions of iOS don't allow to upload files, I need to make a new view (scene I thought it is called) that allows the user to pick and post a picture. I am able to develop both views separately and they work as expected but now I need to connect them based on event triggered when user wants to post a picture to the server. Using shouldStartLoadWithRequest I can catch that action, then I need to redirect to new view (which contains image picker and a button in order to upload the selected image) if iOS version is below 6.0 but I am really lost when it comes to load the new controller to show that view. Using buttons it is trivial but I don't know how to called inside the code. So far, I have a view controller linked to that scene and I have tried these ways:

WritePostViewController *postViewController = [[WritePostViewController alloc] init];
[self.navigationController pushViewController:postViewController animated:YES];

And even calling the storybard:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[sb instantiateInitialViewController];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"WritePostView"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];

The first approach does nothing and second one shows this error log:

* WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: Storyboard () doesn't contain a view controller with identifier 'WritePostView'*

I have been browsing and reading a lot but nothing solves my problem. For sure this a problem with my not-so-large knowledge about iOS but I am really stuck. I will thank any help.

By the way, I need to come back after posting the file but I could imagine it is the same way opposite direction, right?

gnat
  • 6,213
  • 108
  • 53
  • 73
bitsdisasters
  • 253
  • 5
  • 14

2 Answers2

3

If your code is inside a view controller (which it seems to be), you can get the current storyboard with self.storyboard. You also don't need instantiateInitialViewController because, if all your UI is coming from the same storyboard, it has already gone through the loading of the initial controller.

As for the actual error, it's complaining that @"WritePostView" isn't a recognized name for any view controller in the storyboard. Note that what it looks for here is not the class name for the controller but the Storyboard ID for the controller. (Which makes sense since you could have different "scenes" with the same type of controllers.)

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
0

Ok, it seems is solved. I just have added a segue between scenes

segue identifier

and then I just need to add this one:

[self performSegueWithIdentifier:@"writePostViewSegue" sender:self];

and it works!. Anyway, I am not sure if it is the way to do it, so if someone knows better, please let me know.

Cheers

bitsdisasters
  • 253
  • 5
  • 14
  • The answer I posted above assumed that you wanted to use `presentViewController:` in code for some reason. :) If a segue works for you, it's a better solution. – Phillip Mills Nov 02 '12 at 16:04
  • A brief look at the image attached shows a segue loop. Each segue is creating a new copy and stacking every higher instead of re-using the existing controllers. This will cause many problems from "lost" data to rampant memory usage. – DBD Nov 02 '12 at 19:37
  • Yes, I have realized that I must use a modal view and close it after action is done (save a post). I have changed this avoiding segue loop. – bitsdisasters Nov 07 '12 at 10:30