Tag: uicollectionviewcell

出队后,自定义UICollectionViewCell属性为空

所以我有一个UICollectionView和一个自定义的单元格,这一切都显示出来,工作很好。 我在viewDidLoad中注册类: myCollectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:layout]; [myCollectionView setDataSource:self]; [myCollectionView setDelegate:self]; [myCollectionView setBackgroundColor:[UIColor myColor]]; [myCollectionView registerClass:[SBCustomCell class] forCellWithReuseIdentifier:@"Cell"]; 在我的cellForItemAtIndexPath方法中,我将这个单元格出队并设置它的属性并返回它: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cell"; SBCustomCell *cell= [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; [cell setName: "My Name"]; cell.image = [UIImage imageNamed:@"lol.png"]; cell.score = 100.0; cell.backgroundColor=[UIColor whiteColor]; return cell; } 这一切工作正常,它显示在用户界面。 我的问题是,当我在collectionView上设置一个手势识别器,当我长按某个单元格时,我想能够访问它的属性。 […]

ios – Swift – dequeueReusableCellWithReuseIdentifier,collectionViewController的单元格(在UIView中)滚动后不会加载

我有一个ViewController 3视图: 标题(UIView) TabBar(UIView) UIView3(UIView) 在我的UIView3我有一个collectionViewController。 一个关键的因素是,我把我的collectionViewController.scrollEnable = False因为另一方面,当我滚动,只有UIView3滚动,我希望我entier屏幕滚动(这样,如果我们足够的滚动我的标题和Tabbar被隐藏。 所以这就是我所拥有的: 这就是我的屏幕的样子: 这是完美的。 但是 ,当我向下滚动时,这应该是这样的: 但是 ,看起来像这样: 我认为我的问题来自“dequeueReusableCellWithReuseIdentifier”函数,它没有看到我正在滚动,但我不知道如何“刷新”滚动值,因此它加载单元格3-4的末尾,也单元格5- 6。 你有什么主意吗 ?

UICollectionView单元格与图像,在Swift中点击更改背景

我有一个集合视图,看起来像这样: 蓝色的边框是一个图像。 当我按下它们时,我想让文字和图像变暗。 我发现这个问题是类似的: UICollectionView单元格与图像,点击更改背景 它包含在Objective-C中的这个答案 : 如果你有一个CustomCell,你必须有一个CustomCell.m(实现文件)。 在这个文件中join这个,对我来说是简单的方法: -(void)setHighlighted:(BOOL)highlighted { if (highlighted) { self.layer.opacity = 0.6; // Here what do you want. } else{ self.layer.opacity = 1.0; // Here all change need go back } } 我试图添加到我的自定义UICollectionViewCell像这样: import UIKit class DoubleSoundsCollectionViewCell: UICollectionViewCell { @IBOutlet weak var cellLabel: UILabel! func highlighted(highlighted: Bool) { if (highlighted) […]

UICollectionView单元大小ContentView问题

在单元格的故事板中有一个UICollectionViewCell。 前6个单元的单元大小为45个,最后一个单元的单元大小为50个。 故事板单元大小的宽度= 60。 在iOS模拟器4s上运行时,会发生以下问题。 如果您在位置2,4,6处看到单元格,则会出现UICollectionView的红色背景。 我在子类的layoutSubView中获得以下内容。 Frame = {{0, 0}, {50, 60}} Frame = {{0, 0}, {45, 60}} Frame = {{0, 0}, {45, 60}} Frame = {{0, 0}, {45, 60}} Frame = {{0, 0}, {45, 60}} Frame = {{0, 0}, {45, 60}} Frame = {{0, 0}, {45, 60}} – (void)layoutSubviews { [super layoutSubviews]; NSLog(@"Frame […]

收集视图单元格刷新不会发生

加载视图时,我从api调用填充数据并将其显示到单元格中: override func viewDidLoad() { super.viewDidLoad() parseData(urll: url) } 当我使用search栏进行search时,我正在使用以下代码填充一组新的项目: func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { let keywords = searchBar.text let finalKey = keywords?.replacingOccurrences(of: " ", with: "+") let finalurl = "https://api.giphy.com/v1/gifs/search?api_key=0d4f9877de6d4927943adf5a0d20e8a0&q=\(finalKey!)&limit=25&offset=0&rating=G&lang=en" parseData(urll: finalurl) self.view.endEditing(true) } 但是,当它加载新的项目旧的项目不会被删除,我试过使用重新加载数据,但没有奏效。 而且我已经重载了parseData()函数中的数据函数。 parsedata()代码: func parseData(urll : String) { var request = URLRequest(url: URL(string: urll)!) request.httpMethod = "GET" let config = […]

Swift:一个collectionviewcell中的Actionbutton

我有一个button,我编程的一个collectionview单元格中创build。 @IBAction func editButtonTapped() -> Void { print("Hello Edit Button") } Ĵ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let editButton = UIButton(frame: CGRect(x: 8, y: 241, width: 154, height: 37)) editButton.setImage(UIImage(named: "background-1 (dragged).tiff"), for: UIControlState.normal) editButton.addTarget(self, action: #selector(editButtonTapped), for: UIControlEvents.touchUpInside) editButton.tag = indexPath.row editButton.isUserInteractionEnabled = true cell.addSubview(editButton) cell.bringSubview(toFront: editButton) } 但是当我点击button,没有任何反应(它不显示“你好编辑button”)。 […]

如何在Swift中dynamic更改包含UICollectionView单元格的UITableView单元的高度?

目前,我已经将UICollectionViewCellembedded到UITableViewCell的一个部分中的UITableView 。 我知道如何在UITableView另一部分dynamic地改变单元格的高度,因为我在另一个UITableViewCell中有一个UITextView ,它根据UITextView本的大小来dynamic地改变单元格的高度。 我有的问题是关于包含UICollectionViewCell的UITableViewCell 。 我的UICollectionViewCell有一行4个图像,用户可以使用UIImagePickerController通过相机或照片库添加。 目前正如我UICollectionViewCell ,当生成第5张图片时, UITableViewCell的高度保持不变,但用户可以在UICollectionViewCell水平滚动, UICollectionViewCell所示: 我的最终目标是 : 而我的故事板: 相当明显,但如果只有4个图像, UITableViewCell保持与screenshoot 1相同,但是如果UICollectionViewCell的高度改变,单元格的高度将会dynamic改变。 我已经将UICollectionView的滚动方向设置为仅垂直 。 在进一步解释之前,这是我的部分代码: class TestViewController: UITableViewController, UITextFieldDelegate, UITextViewDelegate, UIImagePickerControllerDelegate { override func viewDidLoad() { super.viewDidLoad() …. tableView.estimatedRowHeight = 40.0 tableView.rowHeight = UITableViewAutomaticDimension } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell: UITableViewCell = […]

集合视图单元格不显示在集合视图中?

我使用纯粹的故事板界面构build器创build了一个集合视图。 这是故事板的样子: 我的collections视图的属性也是默认的。 我还没有写任何东西到我的ViewController.swift 。 出于某种原因,当我在我的手机/模拟器上运行,没有任何button显示。

在UICollectionView中删除一个单元格后,单元格布局刷新

我创build了一个dynamic调整单元格高度的UICollectionView。 我正在调整这个单元格的大小: func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let approximatedwidthoftextview = view.frame.width – 70 let size = CGSize(width: approximatedwidthoftextview, height: 1000) let attributes = [NSAttributedStringKey.font: UIFont(name: "Avenir Next", size: 18)] let estimatedFrame = NSString(string: allnotes[indexPath.row].note).boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil) return CGSize(width: view.frame.width, height: estimatedFrame.height + […]

UICollectionviewCellanimation

我想animation的collectionview单元格,animation应该是这样的: 第一个单元出现,然后延迟一段时间后, 第二个单元将出现一些animation ,这将继续像所有的单元格一样。 如何做到这一点?