iPhone 创建嵌套视图

发布于 2024-11-28 17:23:27 字数 816 浏览 3 评论 0原文

我是 iPhone 编程新手。

我想创建具有多个嵌套视图的基于导航的应用程序,其中第一个和第二个是 UITableView 类型,第三个是带有我自己的界面的简单 UIView,这是我在界面生成器中构建的。

当我运行应用程序时,触摸第一个表视图上的行,我转移到第二个,当我触摸第二个表视图上的行时,我转移到第三个,但在第三个视图上我看不到我的界面,我在 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"; 

没关系,伙计们。 我只是没有向我的按钮添加文本,它位于我的视图中,这就是为什么它是空白的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

游魂 2024-12-05 17:23:27

您不需要 [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];
}

如果您只是根据选择创建视图,那就容易得多。

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.

执着的年纪 2024-12-05 17:23:27

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

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.

相守太难 2024-12-05 17:23:27

ReportTypeViewController 真的继承自 UIViewController,还是像您所说的在 IB 中构建的 UIView

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文