选择行加载UIPickerView之后 [英] Select row After UIPickerView is loaded

查看:74
本文介绍了选择行加载UIPickerView之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iphone数据库应用程序加载从表中的数据 UIPickerView

I have an iphone database app that loads a UIPickerView with data from a table. I want to set the selected row to a particular row from the data in another table.

例如:Lets说我有一个 UIPickerView

for example: Lets say I have a UIPickerView that is loaded with X number of names of the iPhone users friends (the number of names is variable, could be 1 or 1000 and all are entered into the DB by the user). The iPhone user has a preference set that their current best friend is TED. I want the UIPickerView to be position to TED when displayed.

我在哪里调用 selectRow

我试过 viewDidAppear c $ c> titleForRow 这导致了各种奇怪的行为。 viewDidLoad viewWillAppear 都不是问题,因为我不知道选择器的数据源中有什么。

I tried in viewDidAppear but it was never called, in titleForRow which caused all kinds of strange behavior. viewDidLoad and viewWillAppear are out of the question because I don't know what's in the datasource to the picker yet.

提前感谢。

推荐答案

数据。我不知道你加载的数据,所以这只是一个模型的应该工作。如果这没有意义,让我知道你在哪里加载数据,所以我可以把它在一起在我的头:)

Call it after you retrieve the data. I don't know where you load the data so this is just a mockup of what should work. If this doesn't make sense, let me know where you are loading data so I can piece it together in my head :)

-(void)viewDidLoad
{
    // load data from sql
    // self.someDataArray = DATAFROMSQL
    [picker reloadAllComponents];
    [picker selectRow:0 inComponent:0 animated:YES];
}

这篇关于选择行加载UIPickerView之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆