2014-10-03 97 views
-1

所以,我有一个应用程序与sqliteDB,填充它来自应用程序,例如名称,姓氏。现在我试着添加一个pickerview到我的表单中,但绝对不知道如何使用它。 这个按钮处理来自textfield的输入数据,我试着在这里添加同样的选择器,但没有任何反应。也许,我会写一些而不是“???” ?已经尝试过“.dataSourse”,没有任何反应。我完全不明白UIPickerView

- (IBAction)saveInfo:(id)sender { 
NSString *query; 
if (self.recordIDToEdit == -1) { 
    query = [NSString stringWithFormat:@"insert into peopleInfo values(null, '%@', '%@', '%@', '%s')", self.txtFirstname.text, self.txtLastname.text, self.txtCategory.text, self.txtPicker.???; 
} 
else{ 
    query = [NSString stringWithFormat:@"update peopleInfo set firstname='%@', lastname='%@', category='%@', suka='%s' where peopleInfoID=%d", self.txtFirstname.text, self.txtLastname.text, self.txtCategory.text, self.txtPicker.???, self.recordIDToEdit]; 
} 

我宣布*选择这样一个选择的价值,但我不知道如何将它添加到我的数据库就像从文本框等数据..

NSString *select = [_array objectAtIndex:[_txtPicker selectedRowInComponent:0]]; 

可所以不要将数据添加到数据库?

+1

呵呵whatt ??以及选取器 – meda 2014-10-03 20:49:28

+0

选取器与出口匹配的txtPicker – 2014-10-03 20:52:04

+0

您正试图将UIPicker放入字符串中?请解释你的目标 – meda 2014-10-03 20:53:46

回答

0

你可以从选定行索引:

- (NSInteger)selectedRowInComponent:(NSInteger)component; 

例如:

int index = [txtPickerselectedRowInComponent:0]; 
self.strTx= [pickerData objectAtIndex:index]; 

或使用委托:

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

基本上,当有人从你的选择器中选择一个项目,只是读取值

self.strTx= [pickerData objectAtIndex:row]; 

所以你有选择