0
我正在將實用程序應用程序模板與Core Data一起使用。在反面視圖中,用戶可以添加項目,這些項目品牌和模型在主視圖上提供UIPickerView。實用程序應用程序模板:如何從flipside視圖刷新UIPickerView
當用戶添加項目時,除非她或他關閉應用程序,否則此添加的項目不會出現在選取器行標題中。
如何在不關閉應用程序的情況下加載此標題? 感謝
編輯添加代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//retrieving data from iGear.xcdatamodeld
iGearAppDelegate *iGearDelegate = [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [iGearDelegate managedObjectContext];
NSError *error;
if (managedObjectContext !=nil) {
if ([managedObjectContext hasChanges] && [managedObjectContext save:&error]) {
//NSLog(@"Retrieving: unresolved error %@, %@",error, [error userInfo]);
abort();
}
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Cogset" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
//#pragma mark UIPickerView
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
return [fetchedObjects count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == 0)
{
cogset = [fetchedObjects objectAtIndex:row];
return [NSString stringWithFormat:@"%@ %@",cogset.brand,cogset.model];
}
return @"";
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
cassette = [fetchedObjects objectAtIndex:[_chooseCogsetPickerView selectedRowInComponent:0]];
}
PickerView上的標題顯示正確,但情況是,我需要刷新主視圖,或在Leat上使用「 - (void)viewWillAppear」方法。如果應用在iPhone上運行,則沒有問題,但在iPad上,用戶可以在彈出窗口中添加數據。也許我應該把這個popover改成一個模態視圖... – Luis 2012-07-13 14:51:49