Tag: uicollectionviewcell

在Swift中的collectionViewCell中caching图像?

我在我的collectionViewCell中有通过NSURLRequest获取和parsing的图像,我如何caching这些图像,以便它们不必在视图的每一次出现/消失都开始一个新的请求? 这里是我的代码,提取图像: class funnyPicture: NSObject { var pfPicture : PFObject var coverImage : UIImage! init(pfPicture: PFObject) { self.pfPicture = pfPicture } func fetchCoverImage(completion: (image: UIImage?, error: NSError?) -> Void) { let urlString = self.pfPicture["funnyPictures"] as! String let url = NSURL(string: urlString) let request = NSURLRequest(URL: url!) let queue = dispatch_get_main_queue() NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response: […]

XCode 6 UICollectionview viewwithtag不起作用

似乎XCode 6是不同的使用viewwithtags然后XCode 5是。 我在故事板中使用XCode 6中的以下代码。 50个单元格被创build,但标签是不可见的。一切正如像标签设置等。如果我使用“旧”XCode 5的方式来做与寄存器单元格分类似乎适用于iOS 7,但在iOS 8的数据没有传递给标签,直到我开始滚动。 static NSString * const reuseIdentifier = @"MyCell"; – (void)viewDidLoad { [super viewDidLoad]; // Register cell classes [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; } – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 50; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = […]

viewWithTag在初始化UICollectionViewCell时返回nil

刚开始使用UICollectionView 。 我用IB在UIViewController创build了一个简单的UICollectionView 。 它与分页水平滚动。 我在UICollectionView放置了一个简单的UICollectionView 。 我为单元格设置了重用标识符。 我在UICollectionViewCell放置了一个标签为100的UICollectionViewCell 。 在viewDidLoad ,我打电话给: [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Thing"]; 后来我尝试初始化单元格,如下所示: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Thing" forIndexPath:indexPath]; cell.backgroundColor = [UIColor greenColor]; UILabel *nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = @"Bogus"; return cell; } 当我运行应用程序,视图加载正确; 我可以水平滚动2个单元格。 我看到了识别每个细胞的难看的绿色。 但是, viewWithTag方法返回nil ,因此nameLabel文本未设置。 为什么? 请注意,我也尝试定义UICollectionViewCell的自定义子类,并调用registerClass。 在IB中,我将单元类更改为自定义子类,并将UILabel绑定到子类的UILabelsockets。 […]

如何使一个collectionViewCell自动resize只有身高?

我使用了collectionView的stream式布局自动化function self.flow = [[UICollectionViewFlowLayout alloc] init]; self.flow.scrollDirection = UICollectionViewScrollDirectionVertical; self.flow.sectionInset = UIEdgeInsetsZero; self.flow.estimatedItemSize = CGSizeMake(320, 48); 我想要单元格将宽度的CollectionView(widthCell = widthCollectionView) 但我得到了整个大小的自动化工作。 我尝试玩内容压缩/拥抱优先 – 不起作用。 对于CollectionView的宽度等于320px,我得到了标签内容大小的单元格大小。 我的单元格看起来像 限制水平:H:| -8- [img(48)] – 8- [标签] -8- | 如何使autosize工作只​​为垂直而不是水平?

UICollectionViewCell自动布局

我在故事板中创build了一个简单的自定义UICollectionViewCell ,我也用相同的结果编程实现了这个function。 它有一个单独的UIImageView和两个UILabels ,如下所示: <–UIIMAGEVIEW–> <–UILABEL——–> |-(10px)- | | -(10px)- -(10px)-| <—————> <–UILABEL——–> 图像坐在左边,然后在右边是两个标签,上下彼此。 每个间隔有10个像素间隙,全部以单元Y轴为中心。 标签然后有一个常数来抵消他们从中心(上下)。 图像的高度和宽度固定为44px,标签的高度固定为20px(宽度可调)。 约束按预期工作,永远不会破坏应用程序,但它们总是吐出下面这个令人讨厌的控制台日志信息,因为它们显然正在破坏。 如果我将这一行添加到我的UICollectionViewCell子类中,约束不再中断并吐出控制台错误,但它们在屏幕上完全被破坏。 [self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; 任何线索? 请帮忙,这似乎是不合逻辑的! 这是控制台错误代码: 2014-10-25 18:28:14.273 Air Plan[1579:580797] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each […]

如何以编程方式启用/禁用UICollectionView中的节标题?

如何以编程方式启用/禁用UICollectionView中的节标题? 在Storyboard(checkbox)中可以很容易地完成,但是在代码中如何做呢?

创buildUICollectionViewCell时,子视图框架不正确

问题 我用自定义的UICollectionViewCell创build了一个UICollectionViewController。 自定义单元格包含一个大的矩形UIView(名为colorView)和一个UILabel(名为nameLabel)。 当该集合首先填充其单元格并打印colorView.frame时,打印的框架具有不正确的值。 我知道他们是不正确的,因为colorView框架比单元格框架本身大,即使colorView得到正确。 但是,如果我滚动collectionView足以触发以前创build的单元格的重用,colorView.frame现在具有正确的值! 我需要正确的框架,因为我想要应用圆angular到colorView图层,我需要正确的coloView大小,以便做到这一点。 顺便说一句,如果你想知道,colorView.bounds也有相同的错误大小值colorView.frame。 这个问题 为什么创build单元格时框架不正确? 现在有一些代码 这是我的UICollectionViewCell: class BugCollectionViewCell: UICollectionViewCell { @IBOutlet weak var colorView: UIView! @IBOutlet weak var nameLabel: UILabel! } 这是UICollectionViewController: import UIKit let reuseIdentifier = "Cell" let colors = [UIColor.redColor(), UIColor.blueColor(), UIColor.greenColor(), UIColor.purpleColor()] let labels = ["red", "blue", "green", "purple"] class BugCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { override func […]

Swift:UICollectionViewCell didSelectItemAtIndexPath更改backgroundColor

我很容易能够在CellForItemAtIndexPath方法中更改单元格的背景颜色 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { cell.backgroundColor = UIColor.blackColor() } 但是,当我尝试更改DidSelectItemAtIndexPath中的颜色不起作用。 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let cell: ButtonCollectionCell = collectionView.dequeueReusableCellWithReuseIdentifier("ButtonCell", forIndexPath: indexPath) as! ButtonCollectionCell { cell.backgroundColor = UIColor.blackColor() } 另外我读的地方,使用didSelectItemAtIndexPath将无法正常工作,因为一旦集合视图开始滚动颜色将改变 什么是在Swift修复? 非常感谢你的帮助

防止在新行开始uicollectionview部分

我在uicollectionview上使用stream布局。 这一切看起来不错,除了似乎开始另一条线上的另一节。 这似乎是一个合理的默认,但我怎么重写这一点,使部分在同一行无缝stream动,就像没有新的部分开始? 谢谢!

在哪里确定一个dynamic大小的UICollectionViewCell的高度?

我正在使用UICollectionViewFlowLayout。 我的单元格包含高度(行数)不同的UILabels。 看来获得单元格高度的最好方法是在UICollectionViewCell的子类中,因为那是我设置布局的位置并且可以访问我的视图的固有尺寸,但是: collectionView: layout: sizeForItemAtIndexPath:在collectionView: cellForItemAtIndexPath: delegate方法之前调用,这意味着我需要知道单元格的高度,然后才能获得单元格的实际布局。 到目前为止,我发现的一切似乎都太复杂了,比如从固定的单元格高度开始,在单元格加载标签之后引用实际高度,然后再次以正确的高度重新加载数据。 有一个更好的方法吗?