簡體   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