gpt4 book ai didi

iphone - Collection View 中的单元格不可见

转载 作者:行者123 更新时间:2023-11-29 13:21:02 24 4
gpt4 key购买 nike

这是 Collection View 的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
...
[_teamsCollection registerClass:[MWTeamCollectionCell class] forCellWithReuseIdentifier:@"Cell"];

}
#pragma mark data source and delegate methods of collection view
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 10;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
MWTeamCollectionCell *cell = [_teamsCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = (MWTeamCollectionCell*)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.teamName.text = @"team name";
return cell;
}

当我调试 return cell; 行时,我得到了正确的日志,但我没有看到单元格。

(gdb) po cell
<MWTeamCollectionCell: 0x72aff80; baseClass = UICollectionViewCell; frame = (0 0; 50 50); layer = <CALayer: 0x72b0090>>
(gdb) po cell
<MWTeamCollectionCell: 0x72b08e0; baseClass = UICollectionViewCell; frame = (67.5 0; 50 50); layer = <CALayer: 0x72b0970>>
(gdb) po cell
<MWTeamCollectionCell: 0x8aad380; baseClass = UICollectionViewCell; frame = (135 0; 50 50); layer = <CALayer: 0x8a72d20>>

最佳答案

不需要像 UITabeView 这样注册类,试试这个:

[yourCollection registerClass:[MWTeamCollectionCell class] forCellWithReuseIdentifier:@"CellName"];

然后

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MWTeamCollectionCell *cell = [yourCollection dequeueReusableCellWithReuseIdentifier:@"CellName" forIndexPath:indexPath];
//Setting some thing here

return cell;

}

够了,记住 MWTeamCollectionCell:UICollectionViewCell 并在 MWTeamCollectionCell.m 中的 (id)init 中自定义(初始化你的 teamName 标签)

UICollectionView 只能在 iOS6 上使用,如果你尝试 iOS5,没有任何显示

关于iphone - Collection View 中的单元格不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14355422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com