[英]Table View doesn't reload data from Parse.com
I have a little problem. 我有一点问题。 So here it is:
所以这里是:
I have a UIViewController with a UITableView (delegate and datasource set). 我有一个带有UITableView(代理和数据源集)的UIViewController。 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中,我从Parse.com查询所有数据并将其存储在多个NSMutableArrays中(我在向它们添加对象之前进行了初始化)
viewDidLoad
: 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.
它可以在TableView中正确显示数据。 However, I have a sliding menu with a TableView with some categories.
但是,我有一个带有一些类别的TableView的滑动菜单。 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.
我NSLogged数组,并且新数据正确。 It shows the right objects from the specific category.
它显示特定类别中的正确对象。
However the TableView doesn't reload. 但是,TableView不会重新加载。 I run
reloadData
on the main thread and i still get no signal from cellForRowAtIndexPath
or numbersOfRowsInSection
. 我在主线程上运行
reloadData
,但仍然无法收到来自cellForRowAtIndexPath
或numbersOfRowsInSection
信号。 I am using a custom UITableViewCell. 我正在使用自定义UITableViewCell。 I don't know if it's related to this, but i tried with simple UITableViewCells and it's still the same issue.
我不知道它是否与此有关,但我尝试使用简单的UITableViewCells,但仍然是相同的问题。 The TableView reloads only when displaying data for the first time.
仅当首次显示数据时,TableView才会重新加载。
This is how I call the searchWithCategory
method from the sliding menu view controller: 这就是我从滑动菜单视图控制器中调用
searchWithCategory
方法的方式:
-(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.
我坚持了大约4天。 Thank you a lot for reading my question!
非常感谢您阅读我的问题!
EDIT: My cellForRowAtIndexPath
method: 编辑:我的
cellForRowAtIndexPath
方法:
- (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
. 您实际上是在使用
titlesArray
将数据填充到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) titlesArray
是否有数据(打印) numberOfRowInSection
from titlesArray.count
titlesArray.count
返回numberOfRowInSection
Try these, hope it will help. 试试看这些,希望对您有所帮助。
Just to clarify your code. 只是为了澄清您的代码。
In the didSelectRowAtIndexPath
you are initializing PlacesViewController
and then running [pvc searchWithCategory];
在
didSelectRowAtIndexPath
您将初始化PlacesViewController
,然后运行[pvc searchWithCategory];
Is implementation of searchWithCategory method in a different file? 在另一个文件中执行searchWithCategory方法吗?
Are the properties titlesArray
thumbnailsArray
etc... global variables? 属性
titlesArray
thumbnailsArray
等是全局变量吗? Why would you need to initialize PlacesViewController
? 为什么需要初始化
PlacesViewController
?
I am guessing this is an IPAD app and you are in the splitviewcontroller
so you can see both controllers? 我猜这是一个IPAD应用程序,您在
splitviewcontroller
因此您可以看到两个控制器? The PlacesViewController
has it's own tableview? PlacesViewController
是否拥有自己的PlacesViewController
?
[self.tableview reload]
that is called in -(void)searchWithCategory
which tableView you are referring? 在
-(void)searchWithCategory
中被称为您要引用哪个tableView?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.