0

I have a little problem. So here it is:

I have a UIViewController with a UITableView (delegate and datasource set). In my ViewDidLoad i query all the data from Parse.com and store it in multiple NSMutableArrays (i initialize before adding object to them)

viewDidLoad:

PFQuery *query = [PFQuery queryWithClassName:@"PlacesClass"];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                for (PFObject *object in objects) {
                    [titlesArray addObject:object[@"PlaceName"]];
                    [thumbnailsArray addObject:object[@"PlaceImageURL"]];      
                 }
                finishedLoading = YES;
                [self.tableView reloadData];
            } else
                NSLog(@"Error: %@ %@", error, [error userInfo]);
        }];

It's working great. It shows the data correctly in the TableView. However, I have a sliding menu with a TableView with some categories. When you tap on one of the categories I do a query again to get all objects with a specific category, like this:

-(void)searchWithCategory{

AppDelegate * delegate = DELEGATE;
_categoryToSearch = delegate.categoryToSearch;

PFQuery *query = [PFQuery queryWithClassName:@"PlacesClass"];
[query whereKey:@"Category" equalTo:_categoryToSearch];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {

        NSMutableArray *titlesArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *thumbnailsArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *facebookArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *twitterArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *addressArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *descriptiomArray2 = [[NSMutableArray alloc]init];
        NSMutableArray *locationArray2 = [[NSMutableArray alloc]init];

        for (PFObject *object in objects) {
            [titlesArray2 addObject:object[@"PlaceName"]];
            [thumbnailsArray2 addObject:object[@"PlaceImageURL"]];
            [facebookArray2 addObject:object[@"PlaceFacebookAddress"]];
            [twitterArray2 addObject:object[@"PlaceTwitterAddress"]];
            [addressArray2 addObject:object[@"PlaceAddress"]];
            [descriptiomArray2 addObject:object[@"PlaceDescription"]];
            [locationArray2 addObject:object[@"PlaceLocation"]];
        }

        titlesArray = titlesArray2;
        thumbnailsArray = thumbnailsArray2;
        descriptiomArray = descriptiomArray2;
        facebookArray = facebookArray2;
        twitterArray = twitterArray2;
        addressArray = addressArray2;
        locationArray = locationArray2;

        finishedLoading = YES;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });

    } else 
        NSLog(@"Error: %@ %@", error, [error userInfo]);
}];
}

I call this method from the sliding view controller's class when a category is selected. I NSLogged the arrays and the new data is correct. It shows the right objects from the specific category.

However the TableView doesn't reload. I run reloadData on the main thread and i still get no signal from cellForRowAtIndexPath or numbersOfRowsInSection. I am using a custom UITableViewCell. I don't know if it's related to this, but i tried with simple UITableViewCells and it's still the same issue. The TableView reloads only when displaying data for the first time.

This is how I call the searchWithCategory method from the sliding menu view controller:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
      AppDelegate * delegate = DELEGATE;
      delegate.categoryToSearch = [_categoriesNames objectAtIndex:indexPath.row];

      PlacesViewController *pvc = [[PlacesViewController alloc]init];
     [pvc searchWithCategory];

}

Do you guys have any suggestions on how to solve this ? I am stucked with this for about 4 days. Thank you a lot for reading my question!

EDIT: My cellForRowAtIndexPath method:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    customCell = (PlacesTableViewCell *)[tableView dequeueReusableCellWithIdentifier: @"PlacesTableViewCell"];
    if (customCell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PlacesTableViewCell" owner:self options:nil];
        customCell = [nib objectAtIndex:0];
    }

    if(finishedLoading == YES){
        customCell.placeName.text = [titlesArray objectAtIndex:indexPath.row];
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[thumbnailsArray objectAtIndex:indexPath.row]]]];
        customCell.thumbnail.image = image;
     }

    if(indexPath.row == titlesArray.count-1)
        finishedLoading = NO;

    return customCell;
    }
4
  • Nowhere in your code I see anything that results in PlacesViewController's view loaded. You need to see results on a tableview that seems to have not been loaded from xib or otherwise. Commented May 4, 2014 at 15:59
  • @mithleshjha My TableView is loaded from Storyboard. I didn't posted the entire ViewDidLoad. I set the delegate and datasource of the tableView. Can you explain me if there is anything else than that ? Thank you Commented May 4, 2014 at 16:06
  • Show your cellforrowatindexpath method.. Commented May 4, 2014 at 17:25
  • @rptwsthi i added the cellforrowatindexpath method.. Commented May 4, 2014 at 17:31

2 Answers 2

1

From your code:

You are actually using titlesArray for populating data to tableView. Although I am still not very sure about the problem but I can provide you a check list, check below :

  • Check if parse returning data (print parse data count after it is retrieved)
  • Then check if you have initialize your array before adding data to it
  • Then check if titlesArray have data in it (print it)
  • Check if you are returning numberOfRowInSection from titlesArray.count

Try these, hope it will help.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you a lot @rptwsthi, but i already did everything you said.
1

Just to clarify your code.
In the didSelectRowAtIndexPath you are initializing PlacesViewController and then running [pvc searchWithCategory]; Is implementation of searchWithCategory method in a different file?
Are the properties titlesArray thumbnailsArray etc... global variables? Why would you need to initialize PlacesViewController?

I am guessing this is an IPAD app and you are in the splitviewcontroller so you can see both controllers? The PlacesViewController has it's own tableview?

[self.tableview reload] 

that is called in -(void)searchWithCategorywhich tableView you are referring?

3 Comments

I am initializing "PlacesViewController" from a class called "LeftPaneViewController", which is the class of the left side panel i was talking about. From that class i am calling the method "[pvc searchWithCategory];", which belongs to "PlacesViewController". Thank you @Yan!
The properties that you listed are not global properties. I initialize "PlacesViewController" on the "LeftPaneViewController" in order to call "PlacesViewController's" method "searchWithCategory". It's not an iPad app. Yes, the PlacesViewController has it's own tableView. The tableView i am refering to is the one on the main screen (PlacesViewController)
Then which tableView you are trying to reload?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.