繁体   English   中英

需要帮助来设置UISegmentedControl

[英]Need Help Setting Up UISegmentedControl

我有一个视图,在其底部的UIToolBar中有一个带有2个细分的UISegmentedControl。 加载后的视图应默认为视图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];
}

是的,您似乎已经解决了自己的问题。 您的两个可交换视图必须位于第三个视图内。 否则,隐藏父视图时,切换控件将被隐藏。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM