【问题标题】:UITableViewController and NavigationControllerUITableViewController 和 NavigationController
【发布时间】:2009-04-11 10:50:07
【问题描述】:

我在将 UITableViewController 推送到 NavigationController 时遇到问题。使用以下代码:

ProblemEditController *problemEditController = [[[ProblemEditController alloc] initWithNibName:@"ProblemEditController" bundle:nil] retain];
problemEditController.problem = [[Problem alloc] init];
[self.navigationController pushViewController:problemEditController animated:YES];
[problemEditController release];

导航控制器按预期工作,但是表格视图未显示。在我的 UITableViewController 上调用 numberOfSectionsInTableView,但未调用 numberOfRowsInSection 和 cellForRowAtIndexPath,并且视图显示为空白。

我有什么明显的遗漏吗?

编辑

我已经更改了 nib 文件中的某些内容(愚蠢地,不记得是什么),现在我看到 numberOfRowsInSection 正在被调用。

【问题讨论】:

    标签: iphone cocoa-touch


    【解决方案1】:

    好的,我发现我做错了什么。我在 nib 中添加了一个 TableViewController,而不仅仅是添加了一个表格视图。

    我基本上搞砸了在 IB 中查看的连接。为了将来参考,这是自定义 UITableViewController 在 IB 中的样子:

    alt text http://pix.im/files/134/scaled.jpg?1239453713

    现在我觉得自己像个白痴。

    【讨论】:

    • 有时,我觉得 Interface Builder 是个障碍,因为 iOS 库中的所有高级示例项目都以编程方式创建了许多控制器,因此有时很难弄清楚 nib 文件的位置存在于整个应用程序生命周期中。
    【解决方案2】:

    现在尝试在 **problemEditController* 上使用保留或释放。

    这段代码对我来说很好用:

    formationsController = [[FormationsController alloc] initWithNibName:@"Formations" bundle:nil];
    [navigationController pushViewController:formationsController animated:YES];
    

    【讨论】:

    • 不幸的是,这不起作用-同样的问题。我不明白为什么调用 numberOfSectionsInTableView 函数时视图没有显示。
    • 尝试使用 prensetModalViewController 显示视图,而不是推送它。看看有没有变化。
    • 同样的事情 - 显示一个空白视图。
    • 我已经更改了 nib 文件中的某些内容(愚蠢地,不记得是什么),我现在看到 numberOfRowsInSection 被调用了。
    • 没有问题!祝你的项目好运。
    猜你喜欢
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多