2011-06-06 33 views
0

这里我创建一个应用程序,我使用Pickerview。我通过此编码成功创建了采集器视图:fetchrequest数组从核心数据中使用选择器视图

(void)viewDidLoad { 

    [super viewDidLoad]; 
    pickerview =[[UIPickerView alloc]init]; 

    pickerview.frame =CGRectMake(180,250, 145, 10); 
    pickerview.showsSelectionIndicator=YES; 

    [self.view addSubview:pickerview]; 
    pickerview.delegate=self; 
    pickerview.dataSource=self; 
    iTeacherAppDelegate* delegate = (iTeacherAppDelegate*)[[UIApplication sharedApplication] delegate]; 
    NSManagedObjectContext *context = [delegate managedObjectContext]; 

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription 
            entityForName:@"Subject" inManagedObjectContext:context]; 
    [fetchRequest setEntity:entity]; 
    ***NSArray *temp = [[context executeFetchRequest:fetchRequest error:nil]retain];*** 
    [fetchRequest release]; 

    } 

在上面的代码中,我找到了来自executefetchrequest的临时数组。我不能在选择器视图中使用这个数组来显示。当我们尝试然后显示可变数据不是一个cfstring

回答

0

您的NSArray * temp是无效的viewDidLoad之外。使它成为你的类的一个属性,并且它们可以在拾取器数据源方法中使用。