iphone - 通过分段控件在标准样式表和分组样式表之间翻转

标签 iphone uisegmentedcontrol uitableview

我希望使用 UISegmentedControl 在同一 View 上的两个表之间翻转。对一张表(加载 View 时的默认设置)进行分组。第二个表应该是普通的(未分组)。 tableView 在 xib 中设置为 Grouped。

现在,我在两组数据之间切换时正在执行 reloadData 操作。所以当然这两个“ View ”都是分组风格的。我知道一旦设置就无法更改 tableView 的样式,但我希望模仿该意图。

我的最好想法是在代码中创建第二个(普通)tableView,然后根据需要在两个 View 之间切换。我可以显示/隐藏(将它们都保留在内存中)或从 superView 添加和删除。

这两个 View 都可能导致用户点击其他推送的 View Controller 。我想保持与链的一致性,包括从 viewControllers 进一步向下链 popToRootViewController 的能力(有问题的 View 距离根向下两到三步)。

在我用这个想法撕毁我的代码之前,我想我应该检查一下其他人的想法。

谢谢!

更新:到达那里。当我想显示普通表格 View 时,我有这个:

PlainViewController *plainViewController = [[PlainViewController alloc] init];
UIView *plainTableView = plainViewController.view;
plainTableView.frame = CGRectMake(320, 0, 320, 480);
[self.view addSubview:plainViewController.view];

加载并显示良好。但是当 PlainViewController 的 didSelectRowAtIndexPath 触发时,它无法加载下一个 View 。 didSelectRowAtIndexPath 正在触发(已记录),但 pushViewController 不执行任何操作;下一个 View 的 viewDidLoad 永远不会触发。

我怀疑 NavigationController 中存在不连续性,但不太确定在哪里修复该问题。

最佳答案

您可以创建一个单独的UIViewController并将其表添加到“主” View 。

PlainTableViewController *ctr = [[PlainTableViewController alloc] init];
[self.view addSubview:ctr.view];
[ctr release];

您还可以轻松地制作此过程的动画:

PlainTableViewController *ctr = [[PlainTableViewController alloc] init];

UIView *plainTableView = ctr.view;
plainTableView.frame = CGRectMake(320, 0, 320, 480);
[self.view addSubview:plainTableView];

[UIView animateWithDuration:0.3
        animations:^{ 
            groupedTableView.frame = CGRectMake(-320, 0, 320, 480);
            plainTableView.frame = CGRectMake(0, 0, 320, 480);}
        completion:^(BOOL finished){[groupedTableView removeFromSuperView];}
];

[ctr release];

注意:您不会将其添加为导航 Controller 中的 View Controller ,因此 popToRootViewController 的所有调用都应指向您的“主” View Controller 。这就是您想要的。

关于iphone - 通过分段控件在标准样式表和分组样式表之间翻转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6877126/

相关文章:

ios - UITapGestureRecognizer 与 didSelectRowAtIndexPath 并发性

iphone - 通过应用程序加载器提交的应用程序的格式?

iphone - 更改地址簿/联系人中的所有号码

iphone - 如何将 double[][] 存储到文件或 iOS 中持久存在的任何内容中?

xcode - 如何切换表格 View 中显示的数据

ios - 使用 UISegmentedControl 改变 Table View 的数据

iphone - 在运行时创建一个类 - 为什么 NSClassFromString AND objc_getclass 返回 nil?

ios - 在 iOS 7 中使用 iOS 6 风格的分段控件?

ios - 以编程方式选择行后未调用 UITableView didDeselectRowAtIndexPath

ios - 如果它们不包含数据,如何自动删除空的 UITableView 单元格?