UITableView 的范围栏像 App Store 一样吗?

发布于 2024-09-08 17:49:53 字数 337 浏览 2 评论 0原文

有谁知道如何向 UITableView 添加范围栏? App Store 应用程序有时会执行此操作,如下图所示。

我想使用此范围栏为 UITableView 中的元素添加排序选项。这比使用带有 UISegmentControl 的工具栏更方便。

我只是不知道如何实现这一点。我什至不知道该元素的名称(我将其称为范围栏,因为它看起来就像 UISearchBar 的范围栏,但事实并非如此)。

显示我想要的图像

Does anyone know how to add a scope bar to a UITableView?
The App Store app does this sometimes, like in the picture below.

I would like to use this scope bar to add sorting options for the elements in the UITableView. This would be more convenient than having a toolbar with a UISegmentControl.

I just don't know how to implement this. I don't even know the name of the element (I'm calling it scope bar because it looks just like the scope bar of a UISearchBar, but it is not).

image showing what I want

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

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

发布评论

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

评论(4

套路撩心 2024-09-15 17:49:53

实际上,与其他人所说的不同,此 UISegmentedControl 的 .segmentedControlStyle 属性设置为未记录的值 7。

 theSegCtrl.segmentedControlStyle = 7;

但是 @Macatomy 的答案对 AppStore 更安全(尽管 Apple 无论如何也无法检测到这一点)。

Actually, unlike what others have said, this UISegmentedControl's .segmentedControlStyle property is set to an undocumented value of 7.

 theSegCtrl.segmentedControlStyle = 7;

But @Macatomy's answer is more AppStore-safe (although Apple can't detect this anyway).

明明#如月 2024-09-15 17:49:53

也许您已经解决了这个问题,但我相信这对其他人会有帮助。

在 TableViewController 中使用的 ViewController 中,您应该插入以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

NSArray *segmentTextContent = [NSArray arrayWithObjects: @"one",@"two",@"three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);

[self.segmentedControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; //changes the default style
self.segmentedControl.tintColor = [UIColor darkGrayColor]; //changes the default color
self.segmentedControl.enabled = true;
self.segmentedControl.selectedSegmentIndex = 0;

return self.segmentedControl;

}

这会插入一个分段控件作为表头,当您到达列表顶部时(如果您愿意)它也会弹起,同时始终会弹起当您在列表中滚动时保持可见。

希望有帮助。

Probably you already solved this issue but I believe this can be helpful for other people.

Inside your ViewController that you use in that TableViewController, you should insert the following code:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

NSArray *segmentTextContent = [NSArray arrayWithObjects: @"one",@"two",@"three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);

[self.segmentedControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; //changes the default style
self.segmentedControl.tintColor = [UIColor darkGrayColor]; //changes the default color
self.segmentedControl.enabled = true;
self.segmentedControl.selectedSegmentIndex = 0;

return self.segmentedControl;

}

That inserts a segmented control as the table header, which (if you wish) will also bounce when you reach the list top and at the same time will always remain visible while you scroll in your list.

Hope it helps.

酷遇一生 2024-09-15 17:49:53

该元素是 UISegmentedControlUISegmentedControlStyleBar 样式。您可以设置 tintColor 属性来获取所需的颜色。只需将视图放在表格视图上方,您就可以获得类似于屏幕截图的内容。

The element is a UISegmentedControl with the UISegmentedControlStyleBar style. You can set the tintColor property to get the color desired. Just put the view above the table view and you can get something that looks like that screenshot.

阿楠 2024-09-15 17:49:53

UISegmentedControl

您创建它,设置建立其段,并设置其代表。然后,每当选定的段发生变化时,代理就会采取某种操作。

UISegmentedControl

You create it, set up its segments, and set its delegate. The delegate then takes some sort of action every time the selected segment changes.

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