【问题标题】:Simple screen refresh in xcodexcode中的简单屏幕刷新
【发布时间】:2014-08-05 14:46:34
【问题描述】:

我有一个带有 json 的场景获得了 Facebook 的点赞。我需要该场景的自动更新(屏幕必须重新加载)。当新数据(在这种情况下 - facebook 喜欢计数已更改)时。我尝试了网络上的所有示例,但无法实现。

ViewController.m:

AFHTTPRequestOperationManager *FaceBookLikes = [AFHTTPRequestOperationManager manager];
NSString *FBlikes = [[NSUserDefaults standardUserDefaults] objectForKey:@"faceBookUrlField"];
NSString *FBLstr = [NSString stringWithFormat:@"http://graph.facebook.com/%@", FBlikes];
[FaceBookLikes GET:FBLstr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

    self.posts = (NSDictionary *) responseObject;
    self.post = self.posts [@"likes"];
    NSLog(@"FB LIKES: %@", self.post);
    labelFacebookLikesCount.text = [NSString stringWithFormat:@"%@", self.post];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

我欢迎任何解决方案:

  1. 当 json 计数发生变化时更新(刷新屏幕)。
  2. 按时间(例如)每 30 秒更新一次。

【问题讨论】:

    标签: objective-c xcode xcode5 afhttprequestoperation


    【解决方案1】:

    您需要使要刷新的任何视图无效。

    所以在你的情况下,

    [self.viewToRefresh setNeedsDisplay];

    在你更新你的价值观后调用它。

    【讨论】:

    • 这仅在相关视图使用-drawRect 进行自定义绘图时才有效。
    • 粘贴到哪里?我收到错误“在 ViewController 类型的对象上找不到属性 ...
    • 也许您可以建议一个简单的场景刷新(按时间)。该怎么做?
    • @МаксимЗуев viewToRefresh 应该替换为您的视图。但是这种方法可能不适用于您的情况(请参阅我之前的评论)。
    猜你喜欢
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多