Metaller
Metaller

Reputation: 514

iPhone creating nested views

I'm noob in iPhone programming.

I want to create navigation-based application with several nested views, when first and second are UITableView-type, and the third is simple UIView with my own interface, which I built in Interface builder.

When I run the App, touch the row on the first table-view I transfer to the second, and when I touch the row on the second, I transfer to the third, but on the third View I don't see my interface, which I built in Interface Builder, just blank screen.

This is part of my code, where I try to call my third view:

    if(self.reportView == nil){    
        ReportTypeViewController *viewController = 
        [[ReportTypeViewController alloc] initWithNibName:@"ReportTypeViewController" 
                                            bundle:[NSBundle mainBundle]];
        self.reportView = viewController;
        [viewController release];        
    }


    [self.navigationController pushViewController:self.reportView  animated:YES];
    self.reportView.title = @"Reports"; 

That's OK, guys. I've just didn't add text to my button, that lies on my view, that's why it was blank.

Upvotes: 1

Views: 296

Answers (3)

nekno
nekno

Reputation: 19267

Does ReportTypeViewController really inherit from UIViewController, or is it a UIView, as you say you built in IB?

navigationController pushViewContoller:animated: needs a UIViewController not a UIView. In IB, you can add a UIViewController and move your UIView onto it, or create it programmatically.

Upvotes: 0

Alex Coplan
Alex Coplan

Reputation: 13371

You don't need [NSBundle mainBundle];

it should look like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ReportViewController *vc = [[ReportViewController alloc] initWithNibName:ReportViewController bundle:nil];
    vc.title = @"Reports";
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}

If you just create the view on demand with the selection it's much easier.

Upvotes: 2

cduhn
cduhn

Reputation: 17918

In IB, make sure you remembered to set the Class of File's Owner to ReportTypeViewController, and make sure that the view outlet of File's Owner is connected to your view.

Upvotes: 2

Related Questions