如何在使用 splitViewController 的 iPad 上引用detailViewController

发布于 2025-01-02 06:39:55 字数 1116 浏览 4 评论 0原文

我在 XCode 4.3 和 IOS 5 上设置了一个项目,没有使用 iPhone 和 iPad 的情节提要,使用创建新项目对话框中的默认主/细节设置。

iPhone端运行得很好。我在 tableView 中选择一个选项,detailViewController 屏幕会根据选择更新新信息。

我的 didSelectRowAtIndexPath 实现是:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
        Shapes *currentShape = [self.shapesArray objectAtIndex:indexPath.row];  
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {  
            if (!self.detailViewController) {  
                self.detailViewController = [[[GeoDetailViewController alloc] initWithNibName:@"GeoDetailViewController_iPhone" bundle:nil] autorelease];  
            }  
            [self.navigationController pushViewController:self.detailViewController animated:YES];  
            [self.detailViewController populateDisplay:currentShape];  
        } else {  
            [self.detailViewController populateDisplay:currentShape];  
        }  
}  

但是,当我在 iPad 上运行时, self.detailViewController 不存在。所以显示不会更新。我仍然可以在 iPad 屏幕上看到它,但我无法更改上面的任何内容。如何在代码中引用它以便可以更改显示的内容?

I setup a project on XCode 4.3 and IOS 5 without using storyboards for both iPhone and iPad using the default Master/Detail setup from the create new project dialog.

The iPhone side works just fine. I select an option in the tableView and the detailViewController screen updates with the new information based on the selection.

My implementation of didSelectRowAtIndexPath is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
        Shapes *currentShape = [self.shapesArray objectAtIndex:indexPath.row];  
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {  
            if (!self.detailViewController) {  
                self.detailViewController = [[[GeoDetailViewController alloc] initWithNibName:@"GeoDetailViewController_iPhone" bundle:nil] autorelease];  
            }  
            [self.navigationController pushViewController:self.detailViewController animated:YES];  
            [self.detailViewController populateDisplay:currentShape];  
        } else {  
            [self.detailViewController populateDisplay:currentShape];  
        }  
}  

However, when I run on the iPad, self.detailViewController does not exist. so the display doesn't update. I can still see it on the iPad screen, I just can't change anything on it. How do I reference it in the code so I can make changes to what is displayed?

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

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

发布评论

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

评论(3

夏末的微笑 2025-01-09 06:39:55

我对主视图/详细视图的模板实现感到困惑。我问了类似的问题:

如何使用 MasterDetail 应用程序模板更新 DetailView

您可以使用为DetailViewController 类默认设置的detailItem(id - 这样您可以传入引用)属性。

I was puzzled by the templates implementation of the Master/Detail view. I asked a similar question:

How to update DetailView using MasterDetail Application Template

You can use the detailItem (id - so you can pass in a reference) property that is set up by default for the DetailViewController class.

空气里的味道 2025-01-09 06:39:55

如果您有指向拆分视图控制器本身的指针,您可以执行以下操作:

[(GeoDetailViewController *)[[(UINavigationController *)[[splitViewController viewControllers] objectAtIndex:1] viewControllers] objectAtIndex:0] populateDisplay:currentShape];

要获取指向拆分视图的指针,您可能必须通过应用程序委托:(

UISplitViewController *splitViewController = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController];

假设您正在使用默认的拆分视图控制器模板 - YMMV取决于您的实现方式)

请注意,当您创建分割视图时,您必须将详细信息视图控制器设置为GeoDetailViewController - 如果您不是并且不能出于应用程序设计的原因,我可以编辑我的工作答案围绕那个。

If you have a pointer to the split view controller itself, you can do:

[(GeoDetailViewController *)[[(UINavigationController *)[[splitViewController viewControllers] objectAtIndex:1] viewControllers] objectAtIndex:0] populateDisplay:currentShape];

To get the pointer to your split view, you will probably have to go via your app delegate:

UISplitViewController *splitViewController = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] splitViewController];

(assuming that you are using the default split view controller template - YMMV depending on how you have implemented it)

Note that when you create your split view, you must set the detail view controller to be a GeoDetailViewController - if you are not and you cannot for app design reasons, I can edit my answer to work around that.

奈何桥上唱咆哮 2025-01-09 06:39:55

在 master/detail 模板中,Apple 在 MasterViewController 中使用以下代码(即左侧的代码):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.detailViewController = (MYDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}

MasterViewController 上的属性定义为:

@property (strong, nonatomic) MYDetailViewController *detailViewController;

In the master/detail template, Apple uses the following code in the MasterViewController (i.e. the one on the left):

- (void)viewDidLoad {
    [super viewDidLoad];
    self.detailViewController = (MYDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}

With the property on MasterViewController defined as:

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