是否可以使用分段控件来更改视图?

发布于 2024-08-28 00:05:03 字数 85 浏览 11 评论 0原文

我想使用分段控件而不是 UITabBar 控制器来更改视图。这符合 HIG 吗?

如果是,我该怎么做?我的项目应该使用什么模板以及什么代码?

i want to use a segmented control instead of a UITabBar controller to change the view. Is that in accordance with the HIG?

If yes, how can I do so? What template should I use for my project and what code?

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

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

发布评论

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

评论(2

有深☉意 2024-09-04 00:05:03

有多个 Apple 应用程序使用分段控件来更改视图:iTunes、App Store 应用程序和 YouTube 应用程序。然而,它们都在屏幕顶部使用它,并与分段控件结合使用。地图应用程序使用屏幕底部的标签栏,但其想法与标签栏不同。日历应用程序还使用一个用于列表、日和月视图(在底部的工具栏中)。

我认为经验法则是,如果您提供同一类型数据的不同视图,则可以使用分段控件。如果您显示的内容不相关,则应该使用选项卡栏。您可能不会因为使用分段控件而拒绝应用程序,但如果您以非标准方式使用它,用户会有点困惑。

我不确定示例代码,我能看到的最接近的是“热门歌曲”示例。这不会交换视图,它只是在单击该段时更改 FetchedResultsController

这是另一个几乎相同的问题:

我该如何使用 UISegmentedControl 来切换视图?

There are several Apple apps that use a segmented control to change the view: iTunes, the App Store app and the YouTube app. However, they all use it at the top of the screen, and in conjunction with a segmented control. The Maps app uses one at the bottom of the screen, but the idea is different from a tab bar. The Calendar app also uses one, for List, Day and Month views (in the toolbar at the bottom).

I think the rule of thumb is that if you're providing different views of the same kind of data, you can use a segmented control. If the things that you're displaying are unrelated, you should use a tab bar. You probably wouldn't have an app rejected for using a segmented control, but users would be a bit confused if you used it in a non-standard way.

I'm not sure about sample code, the closest one I could see is the "Top Songs" sample. That doesn't swap views, it just changes the FetchedResultsController when the segment is clicked on.

Here's another question on SO that's pretty much the same:

How do I use a UISegmentedControl to switch views?

ゝ偶尔ゞ 2024-09-04 00:05:03

我就是这样做的:

-(IBAction)segmentedControlIndexChanged{
switch (self.segmentedControl1.selectedSegmentIndex) {
    case 0:
        [details1 removeFromSuperview];
        [details2 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details0];
        break;
    case 1:
        [details2 removeFromSuperview];
        [details0 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details1];
        break;
    case 2:
        [details0 removeFromSuperview];
        [details1 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details2];
        break;
    case 3:
        [details0 removeFromSuperview];
        [details1 removeFromSuperview];
        [details2 removeFromSuperview];
        [details addSubview:details3];
        break;
    default:
        break;
}
}

确保将 IB 中分段控件的 valueChanged 方法绑定到此 IBAction。

This is how I did it:

-(IBAction)segmentedControlIndexChanged{
switch (self.segmentedControl1.selectedSegmentIndex) {
    case 0:
        [details1 removeFromSuperview];
        [details2 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details0];
        break;
    case 1:
        [details2 removeFromSuperview];
        [details0 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details1];
        break;
    case 2:
        [details0 removeFromSuperview];
        [details1 removeFromSuperview];
        [details3 removeFromSuperview];
        [details addSubview:details2];
        break;
    case 3:
        [details0 removeFromSuperview];
        [details1 removeFromSuperview];
        [details2 removeFromSuperview];
        [details addSubview:details3];
        break;
    default:
        break;
}
}

Make sure you bind the valueChanged method of the segmented control in IB to this IBAction.

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