I am new to iphone development with objective C and XCode 4.2. Right now I successfully instantiated a UITableViewController and it can traverse a multi level json data tree. however, I’m having trouble establish the UI for the leaf page. Let me show you a snippet of code so far:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
int row = [indexPath row];
NSString * currentrow = [NSString stringWithFormat:@"%d.",row];
NSDictionary * item = [dataArray objectForKey:currentrow];
NSDictionary * children = [item objectForKey:@"children"];
if(children != nil)
{
uinavTableViewController *childView = [[uinavTableViewController alloc] init];
childView.dataArray = children;
[self.navigationController pushViewController:childView animated:YES];
}
else
{
uinavMenuItem * childView = [[uinavMenuItem alloc] init];
//uinavSecondViewController * childView = [[uinavSecondViewController alloc] init];
[self.navigationController pushViewController:childView animated:YES];
}
}
So the first part of the if statement will check if there are children nodes, if so create another uinavTableViewController. This part works perfectly.
The else statement creates a leaf page using the uinavMenuItem. When I run this in the simulator, the leaf page is just a black screen. I looked in my NSLog and can confirm that the uinavMenuItem viewDidLoad did get fired. So the controller code is working fine, but i just don’t know how to link up to the view I’ve drawn in the storyboard.
What am I doing wrong that prevents the uinavMenuItem from displaying what I’ve drawn in the storyboarD?
When you want to init a view controller you made in the storyboard, use
UIStoryboard‘s-instantiateViewControllerWithIdentifier. You define this identifier in the storyboard under the view controller’s properties. Your view is loaded but empty because it’s not loading what you have in the storyboard. It’s probably calling-loadViewbecause it cannot find one.Here’s where you enter the identifier: