Instantiating a view controller from another storyboard getting a key value coding-compliant error - ios

I am attempting to add a UITableViewController subclass from another storyboard into the current on as one of the tab bar view controllers.
I am using the following code which is working for other view controllers.
UIViewController *vc;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
if (storyboard)
{
vc = [storyboard instantiateViewControllerWithIdentifier:#"ABCCustomViewControllerStoaryboardID"];
}
This gives me the following error:
* Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key fitnessStatusView.'
The fitnessStatusView is an outlet to a subview of one of the Static cells.
If I remove the outlet connection to this subview the problem goes away.
Is it not possible to connect a view in this way? It works fine when used in the storyboard that it is created in.
Any suggestions as to what I'm doing wrong here? Thanks.

Try this code :
UIStoryboard *loStoryboard ;
loStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
This code for navigate from AppDelegate Class..
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [loStoryboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.view = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
[self.navigationController pushViewController:initialViewController animated:YES];
This code for navigate from Tabbar Controller..
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"ABCCustomViewControllerStoaryboardID"];
[self.navigationController pushViewController:vc animated:YES];

Nope, you're not supposed to attach outlets from View Controllers to UITableViewCell subviews. Yes, I understand that the storboard allows it but it won't work in runtime as you (and I) have already found out.
I don't know why you need an outlet to a static cell subview though, because by definition, you shouldn't have to modify it because it's static.
If you really want an outlet to it, you can create a UITableViewCell subclass, assign it to the cell with the subview you want and then you can create the outlet from the subview in the storyboard to the UITableViewCell subclass. You can access the outlet in tableView:cellForRowAtIndexPath. Although that would make your table view dynamic. :)

I figured out the problem. It was related to the fact I testing another target and the table view subclass was not included in that target.
I must admit it would have been nice if I got a class not found error.

Related

push view controller by search button

i have Storyboard with UINavigationController i have created the first screen with searchbar
i have added second viewcontrol via IB to storyboard
how do i push the second viewcontroller to navigationcontroller ?
i have tried
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
ViewController *screen2 = [[ViewController alloc] initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:screen2 animated:YES];
}
i have set Custom Class of second view controller to ViewController2
but when i run the app and click the search button in keyboard i get the following error
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ViewController2''
The error you are getting is because Xcode cannot find the xib named ViewController2.
You may just call self.performSegueWithIdentifier(#"identifierToViewController")
But first make sure that your searchViewController is a child of an UINavigationController
Then make sure that the segue has a proper identifier:
First of all make sure that your second view controller class name is : ViewController2
After that in storyboard give your View Controller's class name and Storyboard Id as #"ViewController2", Please refer screen shot.
Actually you use wrong method to create instance of UIViewController as it is used when you use xib file.
Change your code like this :
ViewController2 *screen2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[self.navigationController pushViewController:screen2 animated:YES];

Present ViewController on UISplitViewNavigator's MasterViewController

I've created a new XCode project using the SplitViewNavigator template. One of the MasterViewController's navigationItems should present a configuration ViewController (fullScreen on iPhone, popup on iPad).
This config controller has been created in a separate storyboard (Filter.storyboard).
In this storyboard I dragged a ViewController on the stage and embedded it in a Navigation Controller (Editor -> Embed In -> Navigation Controller) because the config itself consists of different screens the user can go through.
The NavigationController has been given a StoryBoard ID "FilterNavController".
I've done this several times in other applications, so this does work. Unfortunately, I can't get it working with the SplitViewNavigator template.
Here is how I try to open the filter controller once the button has been tapped, nothing special about it;
UIStoryboard *filterBoard = [UIStoryboard storyboardWithName:#"Filter" bundle:nil];
UINavigationController *filterNavController = [filterBoard instantiateViewControllerWithIdentifier:#"FilterNavController"];
UIViewController *vc = [filterNavController.viewControllers objectAtIndex:0];
[self.navigationController presentViewController:vc animated:YES completion:nil];
self is the MasterViewController.
From my uneducated point of view, I don't see any reason why this wouldn't work. As I said, it does in other (non SplitViewNavigator template) applications.
The error message I'm getting is the following:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UINavigationController: 0x7f9bab61a700>.'
No idea what the heck is going on here but it already cost me half a day.
Interestingly, when I just create a UIViewController on the Filter.storyboard and set its StoryBoardID, the ViewController will get presented. However, I need it to be embedded in a UINavigationController.
Any help would be highly appreciated!
For the sakes of completeness, the following method works nicely for instantiating ViewControllers from a Storyboard.
Instead of creating a UINavigationController on the Storyboard, just create the ViewController(s) and embed them in a UINavigationController on code.
UIStoryboard *myBoard = [UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
MyViewController *menuController = [myBoard instantiateViewControllerWithIdentifier:#"MyViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myController];
[self presentViewController:navController animated:YES completion:nil];

Property 'navigationController' not found. UIView Interface

I have a storyboard that handles all of my applications UI, apart from the header on each page which is handled by its own .xib file following this guide:
http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/
Within my header .xib I have a button that I want to have when clicked load a view that is part of my story board.
I have tried:
- (IBAction)clicked:(id)sender {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
someViewController *storyViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"someViewController"];
[self.navigationController pushViewController:storyViewController animated:YES];
}
However as my class uses the interface UIView controller navigationController is not found, what can I do to launch a view within the story board from my UIView.
Or if there another interface I can use that will still let me have this as a subview.
what can I do to launch a view within the story board from my UIView
This is bad. A view is a view. Its purpose is to show something to the user, not controlling the app.
UIViewController is where you will need to do this. The navigationController is a property on this class, not on UIView. Read UIViewController class reference for more info.

UITableViewController static cells not appearing when pushed to navigationController

I'm running into a rut...
I've create a UITableViewController with static cells (i've deleted all default UITableView methods). Whenever I segue to this view controller, the static cells appear, but when I push it onto the navigationcontroller the static cells do not appear...any idea to why this would be hapenning?
Here is my code:
//shows empty uitableviewcontroller
OthersUsersTableViewController *tvc = [[OthersUsersTableViewController alloc]init];
[self.navigationController pushViewController:tvc
animated:YES];
and
//works
[self performSegueWithIdentifier:#"toOtherUser" sender:self];
Thanks for the help!
If you manually alloc and init your Static table view, how should your app know that it is referencing a static table view in your storyboard?
Give your static table view an Identifier in the storyboard and initialize it like this:
OthersUsersTableViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:#"staticTableView"];
You can set your identifier in the menu on the right where you also set the custom class for the view controller. The field is called Storyboard ID.
when you're just calling [[UIViewController alloc] init], the UI objects you've added and configured on the storyboard,does not get called or wired to your view controller.
You should instantiate the view controller through the storyboard itself by adding an identifier to your view controller(on the storyboard) and calling instantiateViewControllerWithIdentifier method of your storyboard.
You can get a reference to your storyboard through the current view controller's storyboard property.
OthersUsersTableViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:#"identifier"];

didDeselectRowAtIndexPath not called from UITableViewController added to UIViewController from story board

I am using a split view controller and wanting to add multiple table views to the master view controller.
So I can take advantage of prototype cells that (I believe) you can only get from UITableViewController I have put the UITableViewController into a second storyboard for the app. I am then substantiating it with:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SecondStoryboard" bundle:nil];
MyTableViewController *myTableViewController = [storyboard instantiateInitialViewController];
I then add the view of this UITableViewController as a subview of my UIViewController.
[self.view addSubview:myTableViewController.view];
When I run this, I can select and highlight rows just fine. But didSelectRowAtIndexPath is not being called for some reason?
Thanks for any help,
Richard
Add this line
myTableViewController.view.delegate = myTableViewController;
or Make sure you have done the same in XIB(Interface Builder).
Turns out that I needed to add the uitableviewcontroller as a child controller of the uiviewcontroller as well. Just adding the view alone was not enough.

Resources