簡體   English   中英

UISegmentedControl沒有響應

[英]UISegmentedControl not responding

我以編程方式將UISegmentedControl添加到分組的UITableView的底部。 它顯示的很好,但是當我點擊任何一個選項時,它們都不會突出顯示。 我在這里做錯了什么? 另外,如何設置要突出顯示的默認項目?

- (void)viewDidLoad
{
    [super viewDidLoad];

    // set up cacheControl
    NSArray* cacheDays = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", nil];
    self.cacheControl = [[UISegmentedControl alloc] initWithItems:cacheDays];
    [self.cacheControl setTintColor:[UIColor blackColor]];
    [self.cacheControl addTarget:self action:@selector(cacheSelection:) forControlEvents:UIControlEventValueChanged];
    self.cacheControl.frame = CGRectMake(10, 16, self.tbl.frame.size.width-20, 47);
    [self.cacheControl setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];

}

- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
    switch (section) {
        case 0:{
            UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, tbl.contentInset.top)];
            footerView.backgroundColor = [UIColor clearColor];
            return footerView;
        }
        case 1:{
            UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, 16)];
            footerView.backgroundColor = [UIColor clearColor];

            [footerView setClipsToBounds:NO];

            [footerView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
            [footerView addSubview:self.cacheControl];

            return footerView;
        }
    }
    return nil;
}

屏幕截圖,要求:

設置屏幕

要設置默認項,請執行以下操作: [cacheControl setSelectedSegmentIndex:0]與要選擇的索引。

您應該從UITableViewDelegate協議實現-tableView:heightForFooterInSection:

這將使表格視圖調整節尾的高度以適合您的視圖,並使其能夠接收用戶交互。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM