ViewController标题未更新

时间:2014-04-16 15:10:06

标签: ios objective-c ipad master-detail

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

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

}

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

1 个答案:

答案 0 :(得分:0)

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

在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

相关问题