gng*_*zrd 9 macos cocoa nscollectionview
有一个大脑放屁,无法弄清楚为什么没有调用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
Run Code Online (Sandbox Code Playgroud)
和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
Run Code Online (Sandbox Code Playgroud)
正在调用除集合数据源方法之外的所有内容.
我已经突破并逐步完成所有事情并确保没有零指针.
我检查过并确认IBOutlet不是零.
DribbbleCell类目前没有任何作用,因为我仍在试图弄清楚为什么没有调用这些数据源方法.
我对NSCollectionView缺少什么?
| 归档时间: |
|
| 查看次数: |
2266 次 |
| 最近记录: |