有一个脑屁并且无法弄清楚为什么没有调用NSCollectionView的dataSource方法。
我遇到的NSCollectionView的所有示例都在使用绑定。即使是Apple的“编程指南”也非常简短,而且与其他大多数编程指南相比都很模糊。
我有一个沙盒测试设置只是为了测试它。我正在从dribbble.com加载图片。
这是我的AppDelegate.h:
#import <Cocoa/Cocoa.h>
#import "Dribbble.h"
@interface AppDelegate : NSObject <NSApplicationDelegate,NSCollectionViewDataSource,NSCollectionViewDelegate>
@property IBOutlet NSCollectionView * collectionView;
@end
和AppDelegate.m
#import "AppDelegate.h"
#import "DribbbleCell.h"
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property Dribbble * dribbble;
@property NSMutableArray * dribbbleShots;
@property NSInteger page;
@property NSInteger maxPage;
@end
@implementation AppDelegate
- (void) applicationDidFinishLaunching:(NSNotification *) aNotification {
self.page = 0;
self.maxPage = 1;
self.dribbbleShots = [NSMutableArray array];
self.dribbble = [[Dribbble alloc] init];
self.dribbble.accessToken = @"XXXX";
self.dribbble.clientSecret = @"XXXX";
self.dribbble.clientId = @"XXXX";
NSNib * nib = [[NSNib alloc] initWithNibNamed:@"DribbbleCell" bundle:nil];
[self.collectionView registerNib:nib forItemWithIdentifier:@"DribbbleCell"];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
[self loadDribbbleShots];
}
- (void) loadDribbbleShots {
self.page++;
//this loads 100 shots up to max pages.
[self.dribbble listShotsWithParameters:@{@"per_page":@"100",@"page":[NSString stringWithFormat:@"%lu",self.page]} completion:^(DribbbleResponse *response) {
[self.dribbbleShots addObjectsFromArray:response.data];
if(self.page < self.maxPage) {
[self performSelectorOnMainThread:@selector(loadDribbbleShots) withObject:nil waitUntilDone:FALSE];
} else {
[self finishedDribbbleLoad];
}
}];
}
- (void) finishedDribbbleLoad {
//how do I reload collection view data?
[self.collectionView setContent:self.dribbbleShots];
[self.collectionView reloadData];
[self.collectionView setNeedsDisplay:TRUE];
}
//** None of the below methods are being called.
- (NSInteger) numberOfSectionsInCollectionView:(NSCollectionView *)collectionView {
return 1;
}
- (NSInteger) collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dribbbleShots.count;
}
- (NSCollectionViewItem * ) collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath {
DribbbleCell * cell = (DribbbleCell *)[collectionView makeItemWithIdentifier:@"DribbbleCell" forIndexPath:indexPath];
return cell;
}
@end
正在调用除集合数据源方法之外的所有内容。
我已经突破并穿过所有东西并确保没有零指针。
我已经检查过并确认IBOutlet不是零。
DribbbleCell类目前没有任何作用,因为我仍在试图弄清楚为什么没有调用这些数据源方法。
我对NSCollectionView缺少什么?