开发者

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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜