Implementing a like button - ios

I'm having trouble implementing a working like button in a table cell, using Parse as the backend. There is a button in the tablecell, which is called using a sender/tag. Here's the code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"FeedCell";
FeedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PFObject *post = [postArray objectAtIndex:indexPath.row];
cell.likeForYa.tag = indexPath.row;
[cell.likeForYa addTarget:self
action:#selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
}
In the sender void, here's the code:
-(void)aMethod:(id)sender {
UIButton *senderButton = (UIButton *)sender;
NSLog(#"current Row=%d",senderButton.tag);
PFObject *tempObject = [postArray objectAtIndex:senderButton.tag];
NSLog(#"%#", tempObject.objectId);
//add the object ID for the cell we are liking to the array of liked items in the user class in parse
[[PFUser currentUser]addUniqueObject:tempObject.objectId forKey:#"liked"];
[[PFUser currentUser] saveInBackground];
PFObject* like = [PFObject objectWithClassName:#"Like"];
[like setObject:[PFUser currentUser][#"username"] forKey:#"username"];
[like setObject:tempObject.objectId forKey:#"photo"];
[like saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
PFQuery *query = [PFQuery queryWithClassName:#"Like"];
[query whereKey:#"photo" equalTo:tempObject.objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(#"Number: %lu", (unsigned long)objects.count);
//cell.lik.text = [NSString stringWithFormat:#"%lu",(unsigned long)objects.count];
}];
}];
}
When the button is clicked, nothing is stores and the log for objects.count returns 0. Any ideas?

So here you subclass with PFQueryTableViewController and your tableViewCell may look something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = #"FeedCell";
FeedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[FeedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIButton *likeForYa = [UIButton buttonWithType:UIButtonTypeCustom];
[likeForYa setTag:CellLikeForYaTag];
[cell.contentView addSubview:likeForYa];
[likeForYa addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
}
UIButton * likeForYa = (UIButton*) [cell.contentView viewWithTag:CellLikeForYaTag];
// check if current user like the post and change like-button image accordingly
if ([[object objectForKey:#"whoLiked"]containsObject:[PFUser currentUser].objectId]) {
[likeForYa setImage:[UIImage imageNamed:#"pressedLike.png"] forState:UIControlStateNormal];
} else {
[likeForYa setImage:[UIImage imageNamed:#"unpressedLike.png"] forState:UIControlStateNormal];
}
}
And here's the aMethod:
- (void)aMethod:(UIButton *)button{
CGPoint hitPoint = [button convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
PFObject *object = [self.objects objectAtIndex:hitIndex.row];
// check if current user already liked the post
if (![[object objectForKey:#"whoLiked"]containsObject:[PFUser currentUser].objectId]) {
//add the object ID for the cell we are liking to the array of liked items in the user class in parse
[[PFUser currentUser] addUniqueObject:object.objectId forKey:#"liked"];
[[PFUser currentUser] saveInBackground];
//add the user ID to the post that the user liked
[object addUniqueObject:[PFUser currentUser].objectId forKey:#"whoLiked"];
[object saveInBackground];
} else {
//remove the object ID for the cell we are liking to the array of liked items in the user class in parse
[[PFUser currentUser] removeObject:object.objectId forKey:#"liked"];
[[PFUser currentUser] saveInBackground];
//remove the user ID to the post that the user liked
[object removeObject:[PFUser currentUser].objectId forKey:#"whoLiked"];
[object saveInBackground];
}
[self.tableView reloadData];
}

Alway get aware of result that is throwing error or not.
PFObject* like = [PFObject objectWithClassName:#"Like"];
[like setObject:[PFUser currentUser][#"username"] forKey:#"username"];
[like setObject:tempObject.objectId forKey:#"photo"];
[like saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
//1. Check isSuccess
if (succeeded) {
PFQuery *query = [PFQuery queryWithClassName:#"Like"];
[query whereKey:#"photo" equalTo:tempObject.objectId];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error == nil) {
NSLog(#"Number: %lu", (unsigned long)objects.count);
//cell.lik.text = [NSString stringWithFormat:#"%lu",(unsigned long)objects.count];
}
}];
}
}];
Another thing is make sure your DataTable/Class/Object Structure in the parse.com is matches the name and also type what you are passing here.
Just like
"Like" class that have field "username" and it's type String. And "photo" that have type same like (tempObject.objectId).

Related

UITableViewCell button doesn't show selected or deselected state until scroll

I am working on application with a "like" button in its uitableviewcell, however the state of the cell doesnt show unless the uitableview is scrolled and the cell is off the screen and reappeared. Here is how I am attempting to display the button:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"ProfileCell";
PFObject *data = self.posts[indexPath.row];
NSLog(#"Data: %#", data);
ProfileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[ProfileTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
}
for(UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UIView class]]) {
[view removeFromSuperview];
}
}
#pragma mark - Heart Button
heartButton = [[UIButton alloc] init];
[heartButton setImage:[UIImage imageNamed:#"heartButton"]
forState:UIControlStateNormal];
[heartButton setImage:[UIImage imageNamed:#"heartButtonSelected"]
forState:UIControlStateSelected];
dispatch_async(dispatch_get_main_queue(), ^ {
PFQuery *query = [PFQuery queryWithClassName:#"OrganizationLike"];
[query whereKey:#"Post" equalTo:data];
[query whereKey:#"liker" equalTo:[PFUser currentUser]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject * _Nullable object, NSError * _Nullable error) {
if (!object) {
[heartButton setSelected:NO];
}else{
[heartButton setSelected:YES];
}
}];
});
[heartButton addTarget:self action:#selector(heartButton:) forControlEvents:UIControlEventTouchDown];
[heartButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[cell.contentView addSubview:heartButton];
[heartButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:80];
[heartButton autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:7.0];
[heartButton autoSetDimension:ALDimensionHeight toSize:15];
[heartButton autoSetDimension:ALDimensionWidth toSize:16];
PFQuery *lquery = [PFQuery queryWithClassName:#"OrganizationLike"];
[lquery whereKey:#"Post" equalTo:data];
[lquery findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
if (objects.count>0) {
UILabel *likeLabel = [[UILabel alloc] init];
[likeLabel setNeedsDisplay];
[likeLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
likeLabel.backgroundColor = [UIColor clearColor];
likeLabel.textColor = [UIColor colorWithRed:0.643 green:0.655 blue:0.667 alpha:1];
likeLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:8.881];
likeLabel.textAlignment = NSTextAlignmentCenter;
likeLabel.text = [NSString stringWithFormat:#"%d", objects.count];
[likeLabel setNeedsDisplay];
[cell.contentView addSubview:likeLabel];
[likeLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:heartButton withOffset:0];
[likeLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:heartButton withOffset:3];
}
}];
return cell;
}
Here is how a button tap is handled:
- (void)heartButton:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.selected) {
NSIndexPath *i=[self indexPathForCellContainingView:sender.superview];
PFObject *data = self.posts[i.row];
PFQuery *query = [PFQuery queryWithClassName:#"OrganizationLike"];
[query whereKey:#"Post" equalTo:data];
[query whereKey:#"liker" equalTo:[PFUser currentUser]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject * _Nullable object, NSError * _Nullable error) {
if (!object) {
PFObject *like = [PFObject objectWithClassName:#"OrganizationLike"];
like[#"liker"] = [PFUser currentUser];
like[#"Post"] = data;
[like saveInBackground];
[self.tableView reloadData];
}
}];
} else {
NSIndexPath *i=[self indexPathForCellContainingView:sender.superview];
PFObject *data = self.posts[i.row];
PFQuery *query = [PFQuery queryWithClassName:#"OrganizationLike"];
[query whereKey:#"Post" equalTo:data];
[query whereKey:#"liker" equalTo:[PFUser currentUser]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject * _Nullable object, NSError * _Nullable error) {
[object deleteInBackground];
[self.tableView reloadData];
}];
}
}
reload the table view after the selection or update layout display
First of all try by calling [self.tableView reloadData] in main thread.
Second check if [self.tableView reloadData] gets called. You can check by adding breakpoints.
Rather than reloading the whole tableView cell, you can reload tableView at specific indexpath by calling
[self.tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:nil];
check this this might work,
in - (void)heartButton:(UIButton *)sender
get updated object first and replace it in your main array object
[self.posts replaceObjectAtIndex:index withObject:newObj];
Than use
[self.tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:nil];
And more suggestion there are no need to remove all object first from cell view and than create new in cellForRowAtIndexPath: method instead just check if view object is already exist than just update its value/property

UISwitch changing object parse objective c

I am working on a app that you can change when a item on the menu is in stock or out of stock.
I have it now so it changes the UISwitch to on or off when it loads the screen. I need each switch to change a NSString in parse that makes it one or zero.One meaning that it is on zero meaning its off.
I am fairly new to objective c and parse so if any one could help me get a start on this problem that would be great!
You might use something like that:
PFQuery *query = [PFQuery queryWithClassName:#"YourClass"];
[query whereKey:#"user" equalTo:[PFUser currentUser]];
[query getFirstObjectInBackgroundWithBlock:^(PFObject * yourClass, NSError *error) {
if (!error) {
// Found yourClass object
[yourClass setObject:isInStock forKey:#"isInStock"];
// Save
[yourClass saveInBackground];
} else {
// Did not find any yourClass object for the current user
NSLog(#"Error: %#", error);
}
}];
NSArray *listObjects = .... (loading from Server) // List of PFObject
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
PFObject *object = [listObjects objectAtIndex:indexPath.row];
YourCell *cell = .....
if ([[object valueForKey:#"sandwichesOutofstock"] intValue] == 1)
cell.switch.on = true;
else
cell.switch.on = false;
cell.switch.tag = 500 + index.row;
[cell.switch addTarget:self action:#selector(switchTouch:) forControlEvents:UIControlEventTouchUpInside]
.........
}
(IBAction)switchTouch:(UISwitch *)switch{
long index = switch.tag - 500;
PFObject *object = [listObjects objectAtIndex:index];
if(switch.on)
[object setValue:#"1" ForKey:#"sandwichesOutofstock"];
else{
[object setValue:#"0" ForKey:#"sandwichesOutofstock"];
}
[object saveInBackground];
[self.tableView reloadRowsAtIndexPaths:[NSIndexPath indexPathForRow:index inSection:0] withRowAnimation:UITableViewRowAnimationNone];
}
You could assign a reference of the PFObject to the cell. Then when the switch changes just get the cell's object and make the change.

How to pass a value from NSMutableArray to a PFUser object?

I have a mutable array, called mainArray. It contains a username that is the search result of a user search. I'm displaying every search result in a custom table view cell, that also have a UIButton called addButton. I would like to add the user to the friends list of the current user, when the current user taps the addButton.
The problem is that i can not assign the value from "mainArray" to the "newUser". I've tried some solutions, but the result was always an error or freeze, therefore it would be amazing, if somebody could help me to solve this problem.
My last try wast this line: (it makes this warning: Incompatible pointer types sending NSIndexPath * to parameter of type NSString)
[newUser addUniqueObjectsFromArray:mainArray forKey:indexPath];
.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
mainArray = [[NSMutableArray alloc] initWithObjects:#"User", nil];
self.currentUser = [PFUser currentUser];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [mainArray count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
DevTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"thisCell"];
cell.usernameLabel.text = [mainArray objectAtIndex:indexPath.row];
[cell.addButton addTarget:self action:#selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)didTapButton:(id)sender {
UIButton *button = (UIButton *)sender;
CGPoint pointInSuperview = [button.superview convertPoint:button.center toView:tableView];
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:pointInSuperview];
PFUser *newUser = [PFUser user];
// The problem is here.
[newUser addUniqueObjectsFromArray:mainArray forKey:indexPath];
PFRelation *friendsRelation = [self.currentUser relationForKey:#"friendsRelation"];
if ([self isFriend:newUser]) {
for (PFUser *friend in self.friends) {
if ([friend.objectId isEqualToString:newUser.objectId]){
NSLog(#"some log");
break;
}
}
}
else {
[self.friends addObject:newUser];
[friendsRelation addObject:newUser];
}
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(#"Error %# %#", error, [error userInfo]);
}
}];
}
-(BOOL)isFriend:(PFUser *)newUser {
for (PFUser *friend in self.friends) {
if ([friend.objectId isEqualToString:newUser.objectId]){
return YES;
}
}
return NO;
}
[newUser addUniqueObjectsFromArray:mainArray forKey:indexPath];
You passing NSIndexPathwhere it should be an NSString. You need to convert your indexPath into a string.
So maybe something like this if you want both the section and row to be the key:
NSString *newUserKey = [NSString stringWithFormat:#"%d-%d", indexPath.section, indexPath.row];
[newUser addUniqueObjectsFromArray:mainArray forKey:newUserKey];
EDIT:
You don't have to pass in an array of PFObjects, here is the example from Parse docs:
[gameScore addUniqueObjectsFromArray:#[#"flying", #"kungfu"] forKey:#"skills"];
As you can see they are passing in an array of strings just as you are. I would check to see that your mainArray isn't nil. I've tested this and it works so you are doing something else wrong other than passing in an array of strings.

How to query the user's post?

I currently have my system set up through parse.com
What Im trying to do is to be able to in a tableView or a PFQuerTableViewController be able to query the post which is a PFObject that my user has posted. Currently I have this code below and its only saying "Loading.." instead of displaying their postings. Why is it not displaying my user's last posts?
This is the query in which Im trying to fetch the users post:
- (PFQuery *)queryForTable {
PFQuery *postQuery = [PFQuery queryWithClassName:#"New"];
[postQuery whereKey:#"author" equalTo:[PFUser currentUser]];
// Run the query
[postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Save results and update the table
postArray = objects;
[self.tableView reloadData];
}
}];
}
And here is its cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
// If you want a custom cell, create a new subclass of PFTableViewCell, set the cell identifier in IB, then change this string to match
// You can access any IBOutlets declared in the .h file from here and set the values accordingly
// "Cell" is the default cell identifier in a new Master-Detail Project
static NSString *CellIdentifier = #"Cell";
PFTableViewCell *cell = (PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell
//cell.textLabel.text = [object objectForKey:self.textKey];
//cell.imageView.file = [object objectForKey:self.imageKey];
PFObject *post = [postArray objectAtIndex:indexPath.row];
[cell.textLabel setText:[post objectForKey:#"title"]];
return cell;
}
Also here is the code for how I am posting the PFObject:
-(IBAction)done:(id)sender {
PFUser *user = [PFUser currentUser];
PFObject *quoteNew = [PFObject objectWithClassName:#"New"];
[quoteNew setObject:user forKey:#"user"];
[quoteNew setObject:[[self quoteText] text] forKey:#"quoteText"];
[quoteNew setObject:[[self attributionTitle] text] forKey:#"title"];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Uploading";
[hud show:YES];
[quoteNew saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
//[self done:self];
[hud hide:YES];
[self dismissViewControllerAnimated:YES completion:nil];
} else {
[hud hide:YES];
}
}];
You're trying to run the query in the queryForTable method. That's not what it's for. In queryForTable, you're supposed to build the query with the constraints that you want (like the author thing that you added) then return the query. So for your case:
- (PFQuery *)queryForTable {
PFQuery *postQuery = [PFQuery queryWithClassName:#"New"];
[postQuery whereKey:#"author" equalTo:[PFUser currentUser]];
// Don't run the query, return it so PFQueryTableViewcontroller can use it
return postQuery;
}
If you want to programmatically tell your PFQueryTableViewController to load new posts, you can run [self loadObjects].
Note: This only applies if you are subclassing PFQueryTableViewController
I'd recommend reading the documentation, it lays everything out fairly well here.
You are setting the key as user
[quoteNew setObject:user forKey:#"user"];
Then querying for author
[postQuery whereKey:#"author" equalTo:[PFUser currentUser]];
Try instead
[postQuery whereKey:#"user" equalTo:[PFUser currentUser]];

findObjectsInBackgroundWithBlock shows no results

I am trying to search my objects on parse.com using a uisearchbar and performing 'findObjectsInBackgroundWithBlock'. I am getting the correct results in my output but they are not showing up in my table.
I was previously doing this without blocks, my code worked, it got the correct results but moved very slowly and I was getting a warning, "Warning: A long-running Parse operation is being executed on the main thread"
I had previously been using the code:
- (void)filterResults:(NSString *)searchTerm {
[self.searchResults removeAllObjects];
PFQuery *query = [PFQuery queryWithClassName: #"Items"];
[query whereKeyExists:#"itemName"];
[query whereKeyExists:#"itemDescription"];
[query whereKey:#"tags" containsString:searchTerm];
NSArray *results = [query findObjects];
NSLog(#"%#", results);
NSLog(#"%u", results.count);
[self.searchResults addObjectsFromArray:results];
}
So now I am trying findObjectsInBackgroundWithBlock instead, I have not worked with blocks before so this is where I need help, here is my new code:
- (void)filterResults:(NSString *)searchTerm {
[self.searchResults removeAllObjects];
PFQuery *query = [PFQuery queryWithClassName: #"Items"];
[query whereKey:#"tags" containsString:searchTerm];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(#"%#", objects);
NSLog(#"%u", objects.count);
[self.searchResults addObjectsFromArray:objects];}];
Here is some more of my code
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.tableView) {
return self.objects.count;
} else {
return self.searchResults.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
NSString *uniqueIdentifier = #"cell";
HomeCell *cell = nil;
cell = (HomeCell *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];
if (!cell) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"HomeCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[HomeCell class]])
{
cell = (HomeCell *)currentObject;
break;
}
}
}
if (tableView != self.searchDisplayController.searchResultsTableView) {
NSString *itemName = [object objectForKey:#"itemName"];
NSString *itemDescription = [object objectForKey:#"itemDescription"];
//cell.textLabel.text = last;
cell.cellTitleLabel.text = itemName;
cell.descriptionLabel.text = itemDescription;
cell.priceLabel.text = [object objectForKey:#"price"];
PFFile *thumbnail = [object objectForKey:#"imageFile"];
PFImageView *thumbnailImageView = cell.imageFile;
thumbnailImageView.image = [UIImage imageNamed:#"Facebook #2x.png"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];
}
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {
PFObject *obj2 = [self.searchResults objectAtIndex:indexPath.row];
PFQuery *query = [PFQuery queryWithClassName:#"Items"];
PFObject *searchedItems = [query getObjectWithId:obj2.objectId];
NSString *itemName = [searchedItems objectForKey:#"itemName"];
NSString *itemDescription = [searchedItems objectForKey:#"itemDescription"];
cell.cellTitleLabel.text = itemName;
cell.descriptionLabel.text = itemDescription;
cell.priceLabel.text = [searchedItems objectForKey:#"itemName"];
PFFile *thumbnail = [searchedItems objectForKey:#"imageFile"];
PFImageView *thumbnailImageView = cell.imageFile;
thumbnailImageView.image = [UIImage imageNamed:#"Facebook #2x.png"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];
}
return cell;
Any help would be greatly appreciated,
cheers
In order to update the table view, you need to call the reloadData: method once you have added the new search results. Make sure that you call this method within the block that you provide to findObjectsInBackgroundWithBlock: because this block of code will be run on a separate thread. This causes the method to return instantly, and code after this method will then run before the block has actually executed. Your find objects code within filterResults: should look something like this:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// This block is called from a background thread once the query has been executed
NSLog(#"%#", objects);
NSLog(#"%u", objects.count);
[self.searchResults addObjectsFromArray:objects];
// Refresh the table view on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self.searchDisplayController.searchResultsTableView reloadData];
});
}];
Differentiate from your search table view and your regular tableview when you create the cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
if (tableView = self.tableView) {
//Configure your cell normally
}
else {
//Configure your cells using
cell.someAttribute = self.searchResults[indexPath.row].someAttribute;
}

Resources