gpt4 book ai didi

ios - 我们如何在选择段后调用 PickView 的 didSelectRow?

转载 作者:行者123 更新时间:2023-11-29 11:01:07 24 4
gpt4 key购买 nike

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

这是我的代码:

- (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");
}

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

最佳答案

我认为您需要调用一个方法,该方法具有来自选取器委托(delegate)方法和分段控件的操作方法的所有 [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.

关于ios - 我们如何在选择段后调用 PickView 的 didSelectRow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com