我是Objective-c的初学者,在我的项目中,我想在另一个类中使用NSUserDefaults获取一个类arry-list数据,我在这里做了一些代码,但是它没有用,请帮助我一些
- (IBAction)btnDisplayClicked:(id)sender{
ModelManager *mgrObj=[ModelManager getInstance];
[mgrObj displayData];//Calling here sub class method displayData
NSMutableArray *myArr;
myArr = [[NSMutableArray alloc]init];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
myArr =[userDefaults objectForKey:@"array"];
NSLog(@"array values are %@",myArr);
}
-(void)displayData
{
[instance.database open];
FMResultSet *rs = [instance.database executeQuery:@"SELECT * FROM studentInfo1"];
rowData = [[NSMutableArray alloc] init];
while ([rs next]) {
for(int i=0; i<[rs columnCount]; i++) {
[rowData addObject:[[rs resultDict] objectForKey:[[rs columnNameForIndex:i] lowercaseString]]];
}
}
NSLog(@"%@",rowData);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:rowData forKey:@"array"];
[instance.database close];
}
答案 0 :(得分:0)
试试这个
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:rowData forKey:@"array"];
[userDefaults synchronize];
它会起作用