UIPickerView Selectrow inComponent 没有响应

发布于 2024-11-05 09:17:44 字数 790 浏览 0 评论 0原文

我有标签栏控制器的视图部分。我已将 UIpickerview 添加到视图中。 uipickerview 的委托和数据源是视图控制器。

我有一个这样的编码,

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]; 
     self.arrCurrencies = [[NSMutableArray alloc] init];
    [self.arrCurrencies addObject:@"USD"];
    [self.arrCurrencies addObject:@"GBP"];
    [self.arrCurrencies addObject:@"INR"];
    [self.arrCurrencies addObject:@"EUR"];
    [self.arrCurrencies addObject:@"YEN"];
    [self.arrCurrencies addObject:@"AUD"];
    [self.arrCurrencies addObject:@"SGD"];
    [self.pickerView reloadAllComponents];
    [self.pickerView selectRow:2 inComponent:0 animated:NO];

 }

我尝试了上面的代码,默认情况下它没有在pickerview中选择第三行或INR。有人可以建议我哪里错了..!

I've a view part of tab bar controller. I've added a UIpickerview to the View. The delegate and data source of the uipickerview is the viewcontroller.

I've a coded like this

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]; 
     self.arrCurrencies = [[NSMutableArray alloc] init];
    [self.arrCurrencies addObject:@"USD"];
    [self.arrCurrencies addObject:@"GBP"];
    [self.arrCurrencies addObject:@"INR"];
    [self.arrCurrencies addObject:@"EUR"];
    [self.arrCurrencies addObject:@"YEN"];
    [self.arrCurrencies addObject:@"AUD"];
    [self.arrCurrencies addObject:@"SGD"];
    [self.pickerView reloadAllComponents];
    [self.pickerView selectRow:2 inComponent:0 animated:NO];

 }

I tried the above code, it's not selecting the 3rd row or INR in the pickerview by default. Can someone suggest me where I'm wrong..!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-11-12 09:17:44

我没有看到您的 .delegate 方法,但请确保您按此顺序拥有它:

mypicker.delegate = self;

[mypicker selectRow:[[General sharedInstance] displayMode] inComponent:0 animated:YES];

我在“selectRow”方法之后有委托调用方法,并且我疯狂地在互联网上寻找解决方案。两天时间,想了很多办法,只有这个!!!

所以,这不起作用:

[mypicker selectRow:[[General sharedInstance] displayMode] inComponent:0 animated:YES];
mypicker.delegate = self;

提示:我的类是 UIViewController 子类。

I don't see your .delegate method, but make sure you have it in this order:

mypicker.delegate = self;

[mypicker selectRow:[[General sharedInstance] displayMode] inComponent:0 animated:YES];

I had the delegate call method after the 'selectRow' method and I was mad looking for the solution in internet. 2 days with a lot of solutions, and only was this!!!

So, this doesn't work:

[mypicker selectRow:[[General sharedInstance] displayMode] inComponent:0 animated:YES];
mypicker.delegate = self;

A hint: My class is UIViewController child.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文