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;
}
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 :
titlesArray
have data in it (print it) numberOfRowInSection
from titlesArray.count
Try these, hope it will help.
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)searchWithCategory
which tableView you are referring?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.