iPhone创建嵌套视图

时间:2011-08-10 21:25:00

标签: iphone views controllers

我是iPhone编程的noob。

我想创建具有多个嵌套视图的基于导航的应用程序,第一个和第二个是UITableView类型,第三个是带有我自己的接口的简单UIView,我在Interface builder中构建。

当我运行应用程序时,触摸第一个表格视图中的行我转移到第二个,当我触摸第二个行时,我转移到第三个,但在第三个视图上我看不到我的界面,我在Interface Builder中构建,只是空白屏幕。

这是我的代码的一部分,我尝试调用我的第三个视图:

    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"; 

那没关系,伙计们。 我刚刚没有在我的按钮上添加文字,这就是我的观点,这就是为什么它是空白的。

3 个答案:

答案 0 :(得分:2)

在IB中,请务必记住将文件类别的所有者设置为ReportTypeViewController,并确保文件所有者的view出口已连接到您的视图。

答案 1 :(得分:2)

您不需要[NSBundle mainBundle];

它应该是这样的:

- (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];
}

如果您只是根据需要创建视图,那么选择它会更容易。

答案 2 :(得分:0)

ReportTypeViewController是否真的继承自UIViewController,还是UIView,就像你说你在IB中建造的那样?

navigationController pushViewContoller:animated:需要UIViewController而不是UIView。在IB中,您可以添加UIViewController并将UIView移到其上,或以编程方式创建。

相关问题