Uitableview 加载CoreData对象';将属性转换为UIPickerView
目前,我在CoreData应用程序中有一个名为“事件”的实体。“Events”有一个名为“eventName”的字符串属性 在-(void)viewDidLoad中,我试图获取所有“Events”对象,并按字母顺序将它们的“eventName”加载到UIPickerView中 最终的目标是通过使用文本字段、按钮和正在添加新对象和删除不需要的对象的pickerView。基本上将UIPickerView转换为UITableView。目前,我能够将对象保存到CoreData存储中,但无法将它们/它们的属性提取到UIPickerView中 我愿意并且能够将项目源代码共享给任何想要它的人,或者愿意查看它以帮助解决问题 谢谢 ChrisUitableview 加载CoreData对象';将属性转换为UIPickerView,uitableview,iphone-sdk-3.0,core-data,properties,uipickerview,Uitableview,Iphone Sdk 3.0,Core Data,Properties,Uipickerview,目前,我在CoreData应用程序中有一个名为“事件”的实体。“Events”有一个名为“eventName”的字符串属性 在-(void)viewDidLoad中,我试图获取所有“Events”对象,并按字母顺序将它们的“eventName”加载到UIPickerView中 最终的目标是通过使用文本字段、按钮和正在添加新对象和删除不需要的对象的pickerView。基本上将UIPickerView转换为UITableView。目前,我能够将对象保存到CoreData存储中,但无法将它们/它们的
-(无效)更新
{
NSMutableArray*array2=[[NSMutableArray alloc]init];
CDPickerAppDelegate*appDelegate=[[UIApplication sharedApplication]委托];
NSManagedObjectContext*moc=[appDelegate managedObjectContext];
NSEntityDescription*entityDescription=[NSEntityDescription entityForName:@“事件”在托管对象上下文:moc中];
NSFetchRequest*request=[[[NSFetchRequest alloc]init]autorelease];
[请求集合实体:entityDescription];
NSSortDescriptor*sortDescriptor=[[NSSortDescriptor alloc]initWithKey:@“callName”升序:是];
[请求集合集合描述符:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor发布];
NSArray*数组=[moc executeFetchRequest:请求错误:&错误];
对于(int i=0;i-(void)更新
{
NSMutableArray*array2=[[NSMutableArray alloc]init];
CDPickerAppDelegate*appDelegate=[[UIApplication sharedApplication]委托];
NSManagedObjectContext*moc=[appDelegate managedObjectContext];
NSEntityDescription*entityDescription=[NSEntityDescription entityForName:@“事件”在托管对象上下文:moc中];
NSFetchRequest*request=[[[NSFetchRequest alloc]init]autorelease];
[请求集合实体:entityDescription];
NSSortDescriptor*sortDescriptor=[[NSSortDescriptor alloc]initWithKey:@“callName”升序:是];
[请求集合集合描述符:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor发布];
NSArray*数组=[moc executeFetchRequest:请求错误:&错误];
对于(int i=0;iSo问题是什么?我在下面找到了一些答案,我也发布了代码。但我当前的问题是,是否有可能/如何从UIPickerView中选择的CoreData对象中删除一个?那么问题是什么?我在下面找到了一些答案,我也发布了代码。但是我当前的问题是n是,是否可以/如何从UIPickerView中选择的CoreData对象中删除其中一个?
-(void)update
{
NSMutableArray *array2 = [[NSMutableArray alloc] init];
CDPickerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"callName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
NSArray *array = [moc executeFetchRequest:request error:&error];
for (int i=0; i<array.count; i++) {
Event *theEvent = [array objectAtIndex:i];
NSString *StringOne = [NSString stringWithFormat:@"%@",theEvent.callName];
[array2 addObject:StringOne];
}
self.pickerData = array2;
[singlePicker reloadAllComponents];
}
-(IBAction)addCall{
CDPickerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *theEvent = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:context];
[theEvent setValue:callField.text forKey:@"callName"];
[context save:&error];
callField.text=@"";
[callField resignFirstResponder];
self.update;
}