Iphone 集合视图中的单元格不可见
以下是集合视图的代码:Iphone 集合视图中的单元格不可见,iphone,ios,objective-c,uicollectionview,uicollectionviewcell,Iphone,Ios,Objective C,Uicollectionview,Uicollectionviewcell,以下是集合视图的代码: - (void)viewDidLoad { [super viewDidLoad]; ... [_teamsCollection registerClass:[MWTeamCollectionCell class] forCellWithReuseIdentifier:@"Cell"]; } #pragma mark data source and delegate methods of collection view -(NSInteger)n
- (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;
}
当我调试行返回单元格时代码>,我得到了正确的日志,但我没有看到单元格
(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>>
(gdb)采购订单单元
(gdb)po单元
(gdb)po单元
看起来您正在分配UITableViewCell,而不是UICollectionViewCell
此外,根据您实现自定义收集单元的方式,确保nib已正确解码(加载)。我建议首先使用UICollectionViewCell来验证interface builder中的插座和标识符名称是否正确。看起来您是在分配UITableViewCell而不是UICollectionViewCell
此外,根据您实现自定义收集单元的方式,确保nib已正确解码(加载)。我建议首先使用UICollectionViewCell来验证interface builder中的插座和标识符名称是否正确。不需要像UITableView那样注册类,请尝试以下操作:
[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中进行自定义
UICollectionView仅适用于iOS6,如果您尝试iOS5,则不显示任何内容不需要像UITableView那样注册类,请尝试以下操作:
[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中进行自定义
UICollectionView仅适用于iOS6,如果您尝试iOS5,则不会显示任何内容来替换此行
[yourCollection registerClass:[MWTeamCollectionCell class] forCellWithReuseIdentifier:@"CellName"];
工作线以下
UINib *cellNib = [UINib nibWithNibName:@"MWTeamCollectionCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"CellName"];
对我来说效果很好。更换这一行
[yourCollection registerClass:[MWTeamCollectionCell class] forCellWithReuseIdentifier:@"CellName"];
工作线以下
UINib *cellNib = [UINib nibWithNibName:@"MWTeamCollectionCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"CellName"];
对我来说效果很好。我该怎么做:在interface builder中验证您的插座和标识符名称是否正确?您是对的:)我没有分配UITableViewCell。这是我的新代码(仍然不起作用):()-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{static NSString*CellIdentifier=@“Cell”;MWTeamCollectionCell*Cell=[\u teamsCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];cell.teamName.text=@“team name”;return cell;}如何操作:验证interface builder中的插座和标识符名称是否正确?您是对的:)我没有分配UITableViewCell。这是我的新代码(仍然不起作用):()-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{static NSString*CellIdentifier=@“Cell”;MWTeamCollectionCell*Cell=[\u teamsCollection dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];cell.teamName.text=@“团队名称”;返回单元格;}