Created
May 26, 2014 08:13
-
-
Save nvkiet/29db436e83a406681dbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)refreshData | |
{ | |
PFUser *currentUser = [PFUser currentUser]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"%@ = '%@' OR %@ = '%@'", | |
kMessageUserSendIdKey, currentUser.objectId, | |
kMessageUserReceiveIdKey, currentUser.objectId]]; | |
PFQuery *query = [PFQuery queryWithClassName:kMessageClassKey predicate:predicate]; | |
[query addDescendingOrder:kMessageTimeCreatedKey]; | |
[query includeKey:kMessageUserSendKey]; | |
[query includeKey:kMessageUserReceiveKey]; | |
[query setCachePolicy:kPFCachePolicyCacheThenNetwork]; | |
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { | |
if (!error) { | |
self.messagesDataArray = [NSMutableArray new]; | |
if (objects.count > 0) { | |
[self.messagesDataArray addObject:objects[0]]; | |
for (int i = 1; i < objects.count; i++) { | |
PFObject *messageChat = [objects objectAtIndex:i]; | |
if (![self isExistWithMessageChat:messageChat]){ | |
[self.messagesDataArray addObject:messageChat]; | |
} | |
} | |
[self.tableView reloadData]; | |
} | |
} | |
else { | |
NSLog(@"Error: %@ %@", error, [error userInfo]); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment