Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 更新表视图单元格中的核心数据值后如何刷新_Iphone_Objective C_Core Data - Fatal编程技术网

Iphone 更新表视图单元格中的核心数据值后如何刷新

Iphone 更新表视图单元格中的核心数据值后如何刷新,iphone,objective-c,core-data,Iphone,Objective C,Core Data,我正在我的应用程序中使用核心数据。我有一个双视图控制器,其中一个视图控制器在选择任何一本书后显示书名列表移动到第二个视图控制器,以便使用更新按钮将核心数据表中显示的值更新为1。现在返回到主视图控制器,在选择同一本书后,不会显示secondviewcontroller中的值,但核心数据表的值为1。如何用核心数据表值在表视图中重新加载主viewcontroller。请任何已知的人帮助我 下面是源代码 - (void)viewDidLoad { [super viewDidLoad]; if

我正在我的应用程序中使用核心数据。我有一个双视图控制器,其中一个视图控制器在选择任何一本书后显示书名列表移动到第二个视图控制器,以便使用更新按钮将核心数据表中显示的值更新为1。现在返回到主视图控制器,在选择同一本书后,不会显示secondviewcontroller中的值,但核心数据表的值为1。如何用核心数据表值在表视图中重新加载主viewcontroller。请任何已知的人帮助我

下面是源代码

- (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];
}

从(void)视图调用下面的方法将显示:方法

[self fetchValueFromDatabase];//call this from ViewWillAppear
让我知道它是否有效


快乐编码

您正在viewDidLoad[self-fetchValueFromDatabase]中调用此函数[self.tableview1重新加载数据]这将出现在视图中,这就是您无法在表中获得任何更新的原因

您应该做的是调用[self.tableview1 reloadData]在函数末尾从数据库中获取值

-(void)fetchValueFromDatabase
{

 NSFetchRequest *fech=[[NSFetchRequest alloc]init];
 NSEntityDescription *entity=[NSEntityDescription entityForName:@"Bookname"  inManagedObjectContext:self.managedObjectContext];
 [fech setEntity:entity];
 NSError *savingError=nil;
 ........................
 .......................

 .......................

 [self.tableview1 reloadData];

}

无法重新加载数据。请停止模拟器,然后再次运行模拟器,它将从核心数据表中检索值。您是否收到任何错误或崩溃,按照我说的做。但首先检查您是否使用从coredata更新的同一数组来填充表,如果是,则在调用表上的reloadData之前,先记录您的数组以确保其不为空。无错误。NSLog仅打印最旧的核心数据表值我可以做什么这意味着您的核心数据没有新数据,为了测试一切是否正常,在调用fetchValueFromDatabase之前,请在coredata中添加一个虚拟数据,然后按照我告诉您的那样继续,并在表Delegate numberOfRowsInSection中添加一些NSLogs,希望您是根据更新的数据数组设置行。如果您的表每隔一段时间重新加载新的虚拟数据,则一切正常,并确保您将委托和数据源设置为表的自身