2014-11-24 178 views
1

在视图控制器中有一个UITableView,在上一节的最后一行,有一个Facebook登录和注销按钮作为切换。如果用户登录,会自动退出登录,反之亦然。问题是,当登录控制在Safari中退出应用程序然后返回并查看自动刷新,但注销时UITableView不会重新加载。以下是我使用的代码。刷新UITableView无法正常工作

NSHTTPCookie *cookie; 
     NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
     for (cookie in [storage cookies]) 
     { 
      NSString* domainName = [cookie domain]; 
      NSRange domainRange = [domainName rangeOfString:@"facebook"]; 
      if(domainRange.length > 0) 
      { 
       [storage deleteCookie:cookie]; 
       isFb = 0; 
       [tableView_detailsEdit reloadData]; 
       [[FBSession activeSession] closeAndClearTokenInformation]; 
      } 
     } 
     isFb = 0; 

     [[FBSession activeSession] closeAndClearTokenInformation]; 

     [tableView_detailsEdit reloadData]; 

问题是UITableView委托方法没有被调用。因此,登录后,表格视图中单元格上的文本不会发生变化。 请指导以上内容。

+0

你有没有为自己设定(视图控制器)或任何对象实现的委托方法如表视图的委托? – HAS 2014-11-24 07:27:32

+0

@HAS是的委托设置,这就是为什么tableview工作,如果我滚动uitableview然后值改变,但不是通过调用reloadData自动。 – 2014-11-24 07:50:11

回答

0

使用以下

[[NSOperationQueue mainQueue] addOperationWithBlock:^ { 

    [tableView_detailsEdit reloadData]; 

}]; 

或者

double delayInSeconds = 2.0; 
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
    [tableView_detailsEdit reloadData]; 
});