gpt4 book ai didi

iphone - UICollectionViewContoller单元格格式和安排

转载 作者:行者123 更新时间:2023-12-01 16:46:41 24 4
gpt4 key购买 nike

我已将我的应用设置为从数组中获取数据,并将其放入要在UICollectionViewController中查看的单元格中。我有自定义单元格类,并更改了单元格大小和行数,但未正确显示。我想要5行,并且单元格中的标签有两行。

CollectionViewController.m

#import "CollectionViewController.h"
#import "Cell.h"

@interface CollectionViewController ()

@end

@implementation CollectionViewController

//Delegate Methods

-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}

-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.cellArray.count;
}

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Cell * aCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bingoCell1" forIndexPath:indexPath];
aCell.cellContent.text = self.cellArray[indexPath.row];
return aCell;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

self.cellArray =
@[@"Type 1", @"Type 2", @"Type 3", @"Type 4", @"Type 5", @"Type 6", @"Type 7", @"Type 8", @"Type 9", @"Type 10", @"Type 11", @"Type 12", @"Type 13", @"Type 14", @"Type 15", @"Type 16", @"Type 17", @"Type 18", @"Type 19", @"Type 20", @"Type 21", @"Type 22", @"Type 23", @"Type 24", @"Type 25"];

}

Cell.m
#import "Cell.h"

@implementation Cell

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/

@end

结果表的图像可以在这里找到:
http://i.stack.imgur.com/qmOZp.png

最佳答案

使用以下命令更新您的自定义单元:

#import "Cell.h"


@implementation Cell

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.cellContent.numberOfLines = 2;
self.cellContent.lineBreakMode = NSLineBreakByWordWrapping;
}
return self;
}


-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
dispatch_async(dispatch_get_main_queue(), ^{
self.cellContent.numberOfLines = 2;
self.cellContent.lineBreakMode = NSLineBreakByWordWrapping;
});
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/

@end

关于iphone - UICollectionViewContoller单元格格式和安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19340920/

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