gpt4 book ai didi

ios - viewDidAppear 时如何调用 pickerview 的委托(delegate)?

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

我需要在我的 pickerview 中最后选择的行在 View 出现时被完全召回!我的 viewDidAppear 中有这段代码,它动画到最后选定的行,但它并没有真正调用我行中的 delegateNSLog如果不触摸我的选择器并重新选择它们,将无法打印。

我该怎么做?

- (void)viewDidAppear:(BOOL)animated {

NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
[tasbeehPicker selectRow:[pickerViewSelectionDefaults integerForKey:@"picker"]
inComponent:0 animated:YES];

[pickerViewSelectionDefaults synchronize];
[UIPicker reloadAllComponents];

NSLog(@"Last selcted row was %d ",[[NSUserDefaults standardUserDefaults] integerForKey:@"picker"]);

}

最佳答案

当您通过代码更新选取器时,不应调用委托(delegate)。只有当用户与选择器交互时才会调用委托(delegate)。如果您需要在两种情况下调用相同的代码,请执行以下操作:

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

[myPicker selectRow:4 inComponent:0 animated:animated];
[self handlePickerSelection:myPicker];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[self handledPickerSelection:pickerView];
}

- (void)handlePickerSelection:(UIPickerView *)pickerView {
// process selection
}

关于ios - viewDidAppear 时如何调用 pickerview 的委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16292597/

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