我正在努力将CollectionView添加到我已创建的自定义容器中。我之前使用过Container来托管UITableView,但从来没有使用过CollectionView。它也不是那么难。只是以为我不得不围绕poof切换一些单词它会起作用!但遗憾的是那不是事情的方式。相反,我只是收到崩溃通知。
我的程序一直在崩溃。
//0. Remove the current Detail View Controller showed
if(self.currentDetailViewController){
[self removeCurrentDetailViewController];
}
有人可以帮我理解原因吗?
这是我的代码
#import "YourHome.h"
#import "HomePostTable.h"
#import "HomeStoryView.h"
@interface YourHome ()
@end
@implementation YourHome
-(void)queryParseMethod {
NSLog(@"start query");
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
// [query whereKey:@"photo" equalTo:[PFUser currentUser]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
UsersFilesArray = [[NSArray alloc] initWithArray:objects];
NSLog(@"%@", UsersFilesArray);
//PFObject *imageObject = [PFUser currentUser];
for (PFObject *imageObject in UsersFilesArray) {
// NSLog(@"%@", object.objectId);
PFFile *ImageFile = [imageObject objectForKey:@"photo"];
[ImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
_ProfilePic.image = [UIImage imageWithData:data];
Background.image = _ProfilePic.image;
_ProfilePic.layer.cornerRadius = _ProfilePic.frame.size.width / 2;
_ProfilePic.clipsToBounds = YES;
_ProfilePic.layer.borderWidth = 2.0f;
_ProfilePic.layer.borderColor = [UIColor whiteColor].CGColor;
}
else {
NSLog(@"errrrrrr");
}
}];
}
}
}];
}
- (void)presentDetailController1:(UICollectionViewController*)detailVC{
//0. Remove the current Detail View Controller showed
if(self.currentDetailViewController){
[self removeCurrentDetailViewController];
}
//1. Add the detail controller as child of the container
[self addChildViewController:detailVC];
//2. Define the detail controller's view size
detailVC.view.frame = [self frameForDetailController];
//3. Add the Detail controller's view to the Container's detail view and save a reference to the detail View Controller
[self.detailView addSubview:detailVC.view];
self.currentDetailViewController = detailVC;
//4. Complete the add flow calling the function didMoveToParentViewController
[detailVC didMoveToParentViewController:self];
}
- (void)removeCurrentDetailViewController{
NSLog(@"Go");
//1. Call the willMoveToParentViewController with nil
// This is the last method where your detailViewController can perform some operations before neing removed
[self.currentDetailViewController willMoveToParentViewController:nil];
//2. Remove the DetailViewController's view from the Container
[self.currentDetailViewController.view removeFromSuperview];
//3. Update the hierarchy"
// Automatically the method didMoveToParentViewController: will be called on the detailViewController)
[self.currentDetailViewController removeFromParentViewController];
}
- (CGRect)frameForDetailController{
CGRect detailFrame = self.detailView.bounds;
return detailFrame;
}
- (void)viewDidLoad {
[self queryParseMethod];
HomeStoryView *detailOne = [[HomeStoryView alloc]init];
[self presentDetailController1:detailOne];
}