我在我的应用程序中使用核心数据。我有一个两个视图控制器一个视图控制器在选择书中的任何一个后显示书名列表移动到第二个视图控制器以使用更新按钮将值更新为将显示的 1在核心数据表中。现在回到主视图控制器,在选择同一本书后不会显示第二视图控制器中的值,但核心数据表的值为 1。如何在具有核心数据表值的表视图中重新加载主视图控制器。请任何知道的人帮助我.
下面是源代码
- (void)viewDidLoad
{
[super viewDidLoad];
if(dictionary!=nil)//net is not connected fetch core data to display the booknames
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@" Warning Message" message:@"You are not connect to internet so becoz of loading default values" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[self fetchValueFromDatabase];
}
}
-(void)fetchValueFromDatabase
{
NSFetchRequest *fech=[[NSFetchRequest alloc]init];
NSEntityDescription *entity=[NSEntityDescription entityForName:@"Bookname" inManagedObjectContext:self.managedObjectContext];
[fech setEntity:entity];
NSError *savingError=nil;
NSArray *allBook=[self.managedObjectContext executeFetchRequest:fech error:&savingError];
NSLog(@"Array count value:%i",allBook.count);
coreBookName=[allBook valueForKey:@"bookName"];
NSLog(@"all value:%@",coreBookName);
for(NSString *key in coreBookName)
{
NSLog(@"Key value:%@",key);
[insertBookname addObject:key];
}
coreVoteCount=[allBook valueForKey:@"vote"];
NSLog(@"All vote value:%@",coreVoteCount);
for(NSString *key in coreVoteCount)
{
[bookCount addObject:key];
NSLog(@"Key value:%@",key);
}
for(NSArray *key in allBook)
{
[addItems addObject:key];
NSLog(@"All items:%@",key);
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableview1 reloadData];
}