我无法在cellForItemAtIndexPath(目标C)中收到回调

时间:2017-04-27 01:34:37

标签: ios objective-c callback uicollectionview

我正在尝试使用CollectionView制作应用,但我遇到了问题。从我的代码中可以看出,我在numberofSectionsINCollectionView和numberOfItemsInsection中都收到了回调,但是无法在cellForItemAtIndexPath中接收回调,这使得单元格不会显示在CollectionView中。但是,对于另一台具有相同Xcode版本并连接到同一iPhone(6 Plus)的计算机,我可以在cellForItemAtIndexPath中接收回调。

我不知道为什么。你能告诉我如何解决这个问题吗?我认为它归功于Xcode中的设置,但我不确定。

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
if (self.useSection) {
    return self.dataSource.count;
}
return 1;}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.useSection)
    return [[self.dataSource objectAtIndex:section] count];
return self.dataSource.count; }


 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
 {
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:[self reuseIdentifierForIndexPath:indexPath] forIndexPath:indexPath];
return cell;
 }

我仔细检查委托是否设置为

 self.collectionView.delegate = self;
 self.collectionView.dataSource = self;

1 个答案:

答案 0 :(得分:0)

如果您的单元格大小为(0,0)或计数为0,则不会调用 cellForItemAtIndexPath也许您可以尝试添加此代码:

$.ajax({
  url: "playertwoscript.php",
  method: 'GET/POST',
  data: { test: "test" }
  success: function (data) {}
})