我不理解这个查询我做的和我尝试执行以执行segue的按钮之间的相互关系。
以下是查询
- (void) queryData {
float navBarHeight = self.navigationController.navigationBar.frame.size.height;
float statusHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
float tabBarHeight = self.tabBarController.tabBar.frame.size.height;
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
PFObject *queryPhotos = self.sellerObject;
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
if (self.categoryChosenBool == NO) {
[query whereKey:@"userTookPhoto" equalTo:queryPhotos];
[query includeKey:@"userTookPhoto"];
[query orderByDescending:@"createdAt"];
}
else if (self.categoryChosenBool == YES)
{
[query whereKey:@"userTookPhoto" equalTo:queryPhotos];
[query includeKey:@"userTookPhoto"];
[query whereKey:@"category" containsString:self.chosenCategoryText];
[query orderByDescending:@"createdAt"];
}
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error)
{
if (!error) {
imageFilesArray = [[NSArray alloc] initWithArray:objects];
if ((imageFilesArray.count % 3)) {
CGFloat height = imageFilesArray.count / 3;
CGFloat roundedUp = ceilf(height + 1);
NSLog(@"1 %f",roundedUp + 1);
if (screenSize.height < 569) {
NSLog(@"iphone 5 or 4");
CGFloat cellHeight = roundedUp * 106.5;
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, cellHeight)];
[_contentView setFrame:CGRectMake(0, 0, self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y)];
[_scrollView setContentSize:CGSizeMake(self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y + statusHeight + navBarHeight + tabBarHeight)];
}
else if (screenSize.height > 666){
NSLog(@"iphone 6 or 6Plus");
CGFloat cellHeight = roundedUp * 125;
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, cellHeight)];
[_contentView setFrame:CGRectMake(0, 0, self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y)];
[_scrollView setContentSize:CGSizeMake(self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y + statusHeight + navBarHeight + tabBarHeight)];
}
}else{
CGFloat height = imageFilesArray.count / 3;
CGFloat roundedUp = ceilf(height);
NSLog(@"2 %f",roundedUp);
if (screenSize.height < 569) {
NSLog(@"iphone 5 or 4");
CGFloat cellHeight = roundedUp * 106.5;
if (objects.count < 1) {
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, self.view.frame.size.height - tabBarHeight - statusHeight - navBarHeight - _filterButton.frame.origin.y - _filterButton.frame.size.height )];
}
else{
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, cellHeight)];
[_contentView setFrame:CGRectMake(0, 0, self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y)];
[_scrollView setContentSize:CGSizeMake(self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y + statusHeight + navBarHeight + tabBarHeight)];
}
}
else if (screenSize.height > 666){
NSLog(@"iphone 6 or 6Plus");
CGFloat cellHeight = roundedUp * 125;
if (objects.count < 1) {
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, self.view.frame.size.height - tabBarHeight - statusHeight - navBarHeight - _filterButton.frame.origin.y - _filterButton.frame.size.height )];
}
else{
[_productCollectionView setFrame:CGRectMake(0, _filterButton.frame.origin.y + _filterButton.frame.size.height + 15, self.view.frame.size.width, cellHeight)];
[_contentView setFrame:CGRectMake(0, 0, self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y)];
[_scrollView setContentSize:CGSizeMake(self.view.frame.size.width, cellHeight + _productCollectionView.frame.origin.y + statusHeight + navBarHeight + tabBarHeight)];
}
}
}
[SVProgressHUD dismiss];
[_productCollectionView reloadData];
[self.refreshControl endRefreshing];
}
}];
}
该按钮由以下人员执行:
-(void)executeSegue
{
[self performSegueWithIdentifier:@"nextView" sender:self];
}
在这种情况下,查询为空,但我不明白为什么该方法因此而崩溃。
但是当我注释掉Query时,它完全可以执行segue。
答案 0 :(得分:0)
你不能在后台线程中调用它:
[SVProgressHUD dismiss];
[_productCollectionView reloadData];
[self.refreshControl endRefreshing];
在主线程中使用它。尝试使用此
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
[_productCollectionView reloadData];
[self.refreshControl endRefreshing];
});