【问题标题】:ViewController title not updatingViewController 标题未更新
【发布时间】:2014-04-16 15:10:05
【问题描述】:

我正在使用主从应用程序模板创建一个 iPad 应用程序。在我的 MasterViewController.m 文件中,我有以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.detailViewController.title = @"testing";

}

点击 tableView 中的单元格时,没有任何反应。我做错了什么?

【问题讨论】:

  • 你的detailViewController是什么?是零吗?
  • 不应该是self.title = @"testing";吗?
  • 记录你的DetailVIew,看看结果如何,你如何初始化detailView。当我使用 master-detail 时,我非常依赖委托,这是一个更好的解决方案,可以将对象从 master 设置为 detail,反之亦然。
  • detailViewController 有导航栏吗?如果不是,您可能打算设置 MasterViewController 的标题。
  • 我记录了 detailViewController,它为空。

标签: ios objective-c ipad master-detail


【解决方案1】:

我使用主从应用程序模板创建了一个项目,看看会发生什么。

在 MasterViewController.m 文件中,模板创建以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        NSDate *object = _objects[indexPath.row];
        self.detailViewController.detailItem = object;
    }
}

如果我在上面的方法中添加以下行,self.detailViewController 会更改navigationView 上的标题,正常:

self.detailViewController.title = @"custom title";

不过,这仅在 iPad 上运行应用程序时有效,因为 self.detailViewController 已创建并通过 self.splitViewController 在屏幕上可见。

当您在 iPhone 上运行此应用程序时,self.detailViewController 仅在您单击单元格后创建。因此,self.detailViewController 将是 nildidSelectRowAtIndexPath: 内。点击单元格的动作将触发 Segue Push 动作,这将创建 DetailViewController

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多