在我的应用程序中,我使用PSCollectionView来拥有一个自定义集合视图。我已经准备好创建视图的所有数据,但是当我执行代码时它不会调用该方法
- (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView cellForRowAtIndex:(NSInteger)index`
我在stackoverflow上搜索,发现另一个人有同样的问题(链接),但我不明白他是如何解决的,所以我决定写一个问题来了解如何调用这个方法。我希望有人可以帮助我找到解决此问题的方法。
更新:
这是viewDidLoad
代码:
- (void)viewDidLoad
{
[super viewDidLoad];
tempArray = [[NSMutableArray alloc]init];
self.navBar.title = self.category;
NSString *stringUrl = [NSString stringWithFormat:@"http://54.204.6.246/magento8/api/rest/products/?category_id=%d", self.categoryId];
[self sendRequestToURL:stringUrl withMethod:@"GET"];
// Inizio sezione di codice per la creazione della PSCOLLECTIONVIEW
psView = [[PSCollectionView alloc]init];
// Imposto il delegato per la gestione della scrollView
psView.delegate = self;
// Imposto il delegato per la collection view
psView.collectionViewDelegate = self;
// Imposto il delegato per il data source della collection view
psView.collectionViewDataSource = self;
psView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// Controllo il tipo di device e a seconda del dispositivo trovato creo le colonne e le righe
if ([[UIDevice currentDevice].model isEqualToString:@"iPhone"]) {
psView.numColsPortrait = 2;
psView.numColsLandscape = 4;
} else {
psView.numColsPortrait = 2;
psView.numColsLandscape = 4;
}
// Aggiungo la vista appena creata
[self.view addSubview:psView];
}
这是委托代码:
#pragma mark - PSCollection Delegate e Data Source
- (NSInteger)numberOfRowsInCollectionView:(PSCollectionView *)collectionView {
return [self.arrayWithData count];
}
- (CGFloat)collectionView:(PSCollectionView *)collectionView heightForRowAtIndex:(NSInteger)index {
// NSDictionary *item = [self.arrayWithData objectAtIndex:index];
//
// return [ProductViewCell heightForViewWithObject:item inColumnWidth:psView.colWidth];
return 100.0f;
}
- (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView cellForRowAtIndex:(NSInteger)index {
ProductViewCell *cell = (ProductViewCell *)[psView dequeueReusableViewForClass:nil];
if (!cell) {
cell = [[ProductViewCell alloc]initWithFrame:CGRectZero];
}
cell.labelName.text = [[self.arrayWithData objectAtIndex:index]objectForKey:@"name"];
NSURL * url = [NSURL URLWithString:[[self.arrayWithData objectAtIndex:index]objectForKey:@"url"]];
[cell.productImage setImageWithURL:url
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//[[[SDWebImageManager sharedManager] imageCache] removeImageForKey:yacht.thumbnail fromDisk:NO];
[[[SDWebImageManager sharedManager] imageCache] clearMemory];
}];
return cell;
}