我是(iPhone的新手)開發一款跟蹤數據使用情況(wifi,手機)的iPhone應用程序。我給用戶一個選項來添加新的計劃,這些計劃將被放入數據庫(sqlite)的表中。 我在選取器視圖中顯示計劃列表,我希望在用戶輸入新計劃後立即刷新選取器視圖中的數據。截至目前pickerview被提前 感謝下次運行:(得到更新 代碼是在這裏:如何在不運行應用程序的情況下反映數據庫中的更改?
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
plans= [[NSMutableArray alloc] init];
NSLog(@"Data base is entering");
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"antara" ofType:@"sqlite"];
FMDatabase *db1 = [[FMDatabase alloc] initWithPath:path1];
[db1 open];
FMResultSet *fResult2= [db1 executeQuery:@"SELECT * FROM main"];
NSLog(@"fresult2 ready");
while ([fResult2 next])
{
planData = [fResult2 stringForColumn:@"planName"];
[plans addObject:planData];
NSLog(@"The data is =%@",planData);
}
[db1 close];
[pickerView selectRow:1 inComponent:0 animated:NO];
//mlabel.text= [plans objectAtIndex:[pickerView selectedRowInComponent:0]];
//[self setCurrentPlan:[plans objectAtIndex:[pickerView selectedRowInComponent:0]]];
//[mlabel setText:[self getCurrentPlan]];
currentPlan= [plans objectAtIndex:[pickerView selectedRowInComponent:0]];
[plan setText:currentPlan];
[pickerView release];
請將您的代碼粘貼到您爲picker寫入數據源功能的位置。 –
@rahul:我在問題 –
中添加了代碼好吧,你的代碼看起來很好。問題是什麼時候將數據插入到數據庫中?如果在pickerview當前沒有顯示的情況下將數據插入數據庫,那麼這應該工作得很好。但看看你的問題描述,即使在顯示選擇器視圖時,你似乎也想重新加載數據。這個假設是否正確? –