使用 MGSplitView 控制器更改视图

发布于 2024-11-14 01:45:10 字数 1266 浏览 1 评论 0原文

在 io 正在创建的应用程序中,我有一个 UISplitView 控制器 MGSplitViewController 的自定义副本。我已将其实现到我的项目中,该项目从苹果的 MultipleDetailViews 示例代码开始。

我遇到了一个问题,我似乎无法在视图控制器之间切换。当我推送表格视图单元格时,详细视图控制器应该根据分配的笔尖进行更改,但这不会发生。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

/*
 Create and configure a new detail view controller appropriate for the selection.
 */
NSUInteger row = indexPath.row;

UIViewController *detailViewController = nil;


if (row == 0) {
    FirstDetailViewController *newDetailViewController = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

if (row == 1) {
    SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];

[detailViewController release];

通常,此代码足以更改原始多个详细视图代码中的视图。

有人遇到过类似的问题吗?有什么想法吗?

In the app that io am creating, i have a custom copy of UISplitView Controller, MGSplitViewController. I have implemented it into my project which started off with the MultipleDetailViews sample code from apple.

I have come across a problem where i cant seem to switch between viewcontrollers. When i push the tableview cells, the detailview controller should change according the the nib assigned, however that doesn't happen.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

/*
 Create and configure a new detail view controller appropriate for the selection.
 */
NSUInteger row = indexPath.row;

UIViewController *detailViewController = nil;


if (row == 0) {
    FirstDetailViewController *newDetailViewController = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

if (row == 1) {
    SecondDetailViewController *newDetailViewController = [[SecondDetailViewController alloc] initWithNibName:@"SecondDetailView" bundle:nil];
    detailViewController = newDetailViewController;
}

// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];

[detailViewController release];

Normally this code would be enough to change the views in the original Multiple Detail View code.

has anyone run into a similar problem? any ideas?

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

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

发布评论

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

评论(1

猥︴琐丶欲为 2024-11-21 01:45:10

您只是创建新的视图控制器。您没有将它们添加到任何地方。您可以使用其 viewControllers 属性将视图控制器添加到拆分视图控制器。

编辑:我使用过MGSplitViewController,但我从未尝试过像这样更改详细视图。我刚刚将新的详细视图控制器推送到导航控制器上。是否有特定原因想要完全更改详细视图控制器?

You're just creating new view controllers. You're not adding them anywhere. You add view controllers to the split view controller by using its viewControllers property.

EDIT: I've used MGSplitViewController, but I never tried to change the detail view like that. I just pushed the new detail view controller onto the navigation controller. Is there a specific reason for wanting to change the detail view controller entirely?

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