本文介绍了如何禁用部分控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是的代码UISegmentedControl

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: [UIImage imageNamed:@"down.png"], [UIImage imageNamed:@"dList.png"], nil]];  

[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];  
segmentedControl.frame = CGRectMake(0, 0, 90, 65);  
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;  
segmentedControl.momentary = YES;  

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];  

[segmentedControl release];  

self.navigationItem.rightBarButtonItem = segmentBarItem;  

[segmentBarItem release];    

- (void)segmentAction:(id)sender{

    if([sender selectedSegmentIndex] == 0)
    {
        button.hidden=NO;

    }
    else
    {
        [self dListMethod ];

    }
}

在if()部分我想要禁用 selectedSegmentIndex == 0 并在时启用button.hidden = YES

In the if() section I want to disable selectedSegmentIndex==0 and enable when button.hidden=YES

推荐答案

使用 setEnabled:forSegmentAtIndex:方法启用和禁用细分。

Use setEnabled:forSegmentAtIndex: method to enable and disable the segments.

[segmentedControl setEnabled:NO forSegmentAtIndex:0];

如果你想禁用第一段。

这篇关于如何禁用部分控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:31