我完全不了解UIPickerView

时间:2014-10-03 20:46:16

标签: ios sqlite uipickerview

所以,我有一个带有sqliteDB的应用程序,它来自App,例如Name,Lastname。现在我正在尝试在我的表单中添加一个pickerview,但绝对不知道如何使用它。 这个按钮处理来自textfield的输入数据,我尝试在这里添加相同的选择器,但没有任何反应。也许,我会写一些而不是“???” ?尝试过“.dataSourse”,没有任何反应。!

- (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 个答案:

答案 0 :(得分: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];

所以你可以选择

相关问题