1

我使用分段控件供用户在选择器视图中选择一行后在两种类型的结果之间进行选择。但是,当我在选择器视图中选择一行时,它会显示所选段的结果,但我选择另一个段时它不会做任何事情,直到我再次重新选择该行。

这是我的代码:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

i=row;
switch (i) {
    case 0:


case 1
if(_segment.selectedSegmentIndex == 1){

        [self Fquarter];
        [self Tquarter];
        [self Ten];
        [self Twenty];
        [self Fourty];
        [self Fifty];


        NSLog(@"AUDIO 10 MINS");
        }

        if(_segment.selectedSegmentIndex == 0){

            [self SFquarter];
            [self STquarter];
            [self STen];
            [self STwenty];
            [self SFourty];
            [self SFifty];

             NSLog(@"Visual 10 MINS");
        }

每个案例都是这样,我错过了什么?

4

1 回答 1

2

我认为您需要从选取器委托方法和分段控件的操作方法中调用一个包含所有 [self Fquarter] 等语句的方法。像这样的东西(pickerSelectedRow 是一个类型为 NSInteger 的属性):

@interface ViewController ()
@property (weak,nonatomic) IBOutlet UISegmentedControl *segment;
@property (nonatomic) NSInteger pickerSelectedRow;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    self.pickerSelectedRow = row;
    [self doStuff];

}

-(IBAction)segmentChosen:(UISegmentedControl *)sender {
    [self doStuff];
}


-(void)doStuff {
    switch (self.pickerSelectedRow) {
        case 0:

        case 1:
            if(_segment.selectedSegmentIndex == 1){

                [self Fquarter];
                [self Tquarter];
                [self Ten];
                [self Twenty];
                [self Fourty];
                [self Fifty];


                NSLog(@"AUDIO 10 MINS");
            }

            if(_segment.selectedSegmentIndex == 0){

                [self SFquarter];
                [self STquarter];
                [self STen];
                [self STwenty];
                [self SFourty];
                [self SFifty];

                NSLog(@"Visual 10 MINS");
            }


    }
}

With this type of arrangement, the method where you set your values is called either when the picker view value changes or the segmented control's value changes.

于 2013-04-08T23:52:22.530 回答