【问题标题】:Need Help Setting Up UISegmentedControl需要帮助设置 UISegmentedControl
【发布时间】:2011-06-23 23:27:47
【问题描述】:

我有一个视图,它的底部 UIToolBar 中有一个 UISegmentedControl,它有 2 个段。加载时的视图应默认为查看1.然后选择段2时,应切换到查看2等。

现在,当我单击段 2 时,它会隐藏视图 1,然后切换到第二个视图,但是如何保持 segmentedControl 显示?当视图 1 被隐藏时,控件也被隐藏。

我需要总共创建 3 个视图吗?并将视图 1 和 2 作为默认视图的子视图,其中只有分段控件?

编辑:

- (void)segmentedControl:(SVSegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)index
{
    LogResultsViewController* v1 = [[LogResultsViewController alloc] initWithNibName: @"LogResultsViewController" bundle:nil];
    CalendarController* v2 = [[CalendarController alloc] initWithNibName: @"CalendarController" bundle:nil];

    if (index == 0)
    {
        [self.view addSubview: v1.view];      
    }
    else
    {
        [self.view addSubview: v2.view];
    }
}

这是用于加载此视图的代码:

- (void)loadView 
{
    UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(dismissCalendarView)];
    self.navigationItem.leftBarButtonItem = actionButton;
    [actionButton release];

    int statusBarHeight = 20;
    CGRect applicationFrame = (CGRect)[[UIScreen mainScreen] applicationFrame];
    self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, statusBarHeight, applicationFrame.size.width, applicationFrame.size.height)] autorelease];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.view.backgroundColor = [UIColor grayColor];
    calendar.frame = CGRectMake(0, 0, calendar.frame.size.width, calendar.frame.size.height);

    [self.view addSubview:calendar];
    [calendar reload];
}

【问题讨论】:

    标签: iphone objective-c xcode uiview uisegmentedcontrol


    【解决方案1】:

    是的,您似乎已经解决了自己的问题。您的两个可交换视图需要位于第三个视图内。如果没有,当父视图隐藏时,您的切换控件将被隐藏。

    【讨论】:

    • 谢谢,你能检查一下我发布了一些更新代码的问题吗?
    • 当然,现在会发生什么以及您的新代码应该会发生什么?
    【解决方案2】:

    是的,这正是您需要做的。设置一个包含工具栏和其他视图的容器视图。然后根据需要添加和删除其他两个视图作为容器视图的子视图。

    【讨论】:

    • 谢谢,你能检查一下我发布了一些更新代码的问题吗?
    猜你喜欢
    • 2021-12-13
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多