开发者

Is it possible to use a Segmented Control to change the view?

i want to use a segmented control instead of a UITabBar contr开发者_如何学Coller 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?


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜