Tag: uicollectionview

使用单个表视图控制器为每个集合视图单元格按下

我有5个收集视图单元名称“餐馆”,“商店”,“医疗”,“客厅”,“公园”等。 所以,现在我设置,10视图控制器,我把表视图里面每五个控制器,我打电话json数据和显示在表视图。 我也有一个自定义单元格,我在这里使用所有的控制台表格视图 就像说,如果用户按, Restaurant ,我将redirect到一个视图controlellr。在那个我已经叫`baseurl / category_01的webservies。 所以从这个url我将获取名称,地址,图像,我会显示在我的表格视图 但我知道这是做错的方法。如果我有20个集合视图单元格。那么如果我创build20个视图控制器与20个表视图意味着将不好。 这是我在swift 2.0中的第一个应用程序。 任何人可以build议我使用单视图controlellr与一个表视图我所有的10个单元的集合视图数据。 但是,我收集查看单元格数据中的一件事是我从一个json url中获取。在每个数据被指定为一个类别id.Like: [ { category_id : 0 category_name : Restaurant }, { category_id : 1 category_name : park }, { category_id : 2 category_name : shops }, { category_id : 3 category_name : medical }, ] 像明智的10单元格数据,我将显示在表视图。所以当我使用一个视图controllelr与一个表视图我需要提及,哪个indespath.row按,这应该等于我的类别id和shoyld显示相关数据。 现在我在我的collectionviewcontroller.swift使用的是。我只是哪个索引path行按,我只是导航到另一个视图控制器 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath […]

如何将数据传递给embedded在TableViewCell中的UICollectionView(xCode – iOS – Swift 3)

我在TableViewCell中实现了一个CollectionView,但是我需要为CollectionView上的单元格读取dynamic数据。 我可以从类TableViewCell读取扩展数据,也许可以帮助我从ViewController传递数据到类TableViewCell。 class MultipleTableViewCell: UITableViewCell { @IBOutlet fileprivate weak var collectionView: UICollectionView! } extension MultipleTableViewCell : UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 3 // array.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "foodCell", for: indexPath) as! UserCollectionViewCell let dict = […]

设置集合视图单元格的dynamic宽度和高度

其实我想dynamic设置button和button的标题出现dynamic我已经尝试这个,并获得dynamic内容的宽度,但不是设置单元格的宽度和高度。 – (void)viewDidLoad { [super viewDidLoad]; ContentArray = [[NSMutableArray alloc]init]; self.collectionview.delegate = self; self.collectionview.dataSource =self; self.collectionview.backgroundColor = [UIColor clearColor]; [ContentArray addObject:@"Planning"]; [ContentArray addObject:@"Resources"]; [ContentArray addObject:@"Human Resources"]; [ContentArray addObject:@"Agriculture"]; [ContentArray addObject:@"Resources management"]; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return ContentArray.count; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell"forIndexPath:indexPath]; [Cell.button setTitle:[ContentArray […]

没有CollectionView目录中的图片

我想显示我的目录中的所有图片,但是我正在创build目录中的文件夹,以便我可以对图片进行sorting。 我想在几个文件夹中显示所有的图片。 我正在使用的代码 – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. allImagesArray = [[NSMutableArray alloc] init]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *location=@"Bottoms"@"Top"@"Right"@"Left"@"Down"@"Up"; NSString *fPath = [documentsDirectory stringByAppendingPathComponent:location]; NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: fPath]; collectionTrash.delegate =self; collectionTrash.dataSource=self; for(NSString *str in directoryContent){ NSLog(@"i"); […]

删除最后一个UICollectionViewCell时出现NSRangeException

我有一个UICollectionView 1节。 用户可以从集合中删除单元格,并使用以下代码进行删除: [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:i inSection:0]]]; [self.media removeObjectAtIndex:i]; } completion:nil]; 这对每个单元格都适用,除了集合中的最后一个单元格,每次出现错误都会崩溃应用程序: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2] NSZombies没有显示我的堆栈跟踪,所以我在我的代码中访问数组,但没有被命中的每一行上放置一个断点,我发现这个错误是在deleteItemsAtIndexPaths , numberOfSectionsInCollectionView和sizeForItemAtIndexPath ,但在numberOfItemsInSection和cellForItemAtIndexPath 什么可能导致这次崩溃? 我怎样才能debugging它? 有一些类似的SOpost,但这个从2年前没有回应UICollectionView崩溃时删除最后一个项目 ,这一个只解决了这个问题,如果你想删除整个部分: 删除UICollectionView中的最后一个单元格崩溃 更新,这里是在崩溃之前运行的数据源委托方法: – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath […]

使用多个UICollectionView,出现错误,“…必须用非零布局进行初始化”

我最近开始使用Swift,我试图从页面上的一个UICollectionView(工作)到其中的两个。 我收到错误 “终止应用程序,由于未捕获的exception' NSInvalidArgumentException',原因:'UICollectionView必须使用非零布局参数初始化 '”。 到目前为止,我发现堆栈溢出已经被合并到我的代码中,但我仍然收到错误。 我在智慧的结尾,请帮助! 我去过的地方: 我开始设置UICollectionView 这篇文章 ,一切工作得很好。 现在在同一个屏幕上设置第二个UICollectionView,我按照本文中的说明操作。 一切似乎没问题,我得到“build设成功”,随着应用程序开始运行,迅速崩溃。 错误信息说: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter' 在StackOverflow中寻找这个错误,我发现这篇文章 (处理单个UICollectionView,而不是我有两个)。 我已经从那篇文章中实现了我所能做到的一切,但是我仍然遇到了这个错误,现在已经没有想法了。 我的代码如下,任何帮助将非常感激! ViewController.swift : import UIKit class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { var collectionViewLeft = UICollectionView() // changed "let" to "var" […]

手动滚动显示相同内容的两个UICollectionViews

正如标题所示,我有一个UIViewController与两个UICollectionViews以水平方式显示相同的内容。 主要一次显示一张照片,大拇指显示几张。 我已经重写了UIScrollViewDelegate方法,并添加了一些代码,以便当用户滚动主要的CV,然后拇指CV也滚动。 不过,我想要启用相反的方式(滚动拇指,这将快速移动主)。 不过,我收到了反馈的效果。 这是我的代码片段: #pragma mark – UIScrollViewDelegate – (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if(scrollView == self.mainCollectionView){ CGFloat x = self.mainCollectionView.contentOffset.x / self.mainCollectionView.bounds.size.width * SM_IPHONE_THUMB_CONTAINER_SIZE; // cell width + spacing 48 + 8 CGFloat y = 0; CGPoint contentOffset = CGPointMake(x, y); self.thumbsCollectionView.contentOffset = contentOffset; } else if(scrollView == self.thumbsCollectionView){ // CGFloat x = self.thumbsCollectionView.contentOffset.x / […]

在UICollectionView中重载UILabel

我正在使用UICollectionView 。 在收集视图标签是每次我使用这个代码过载 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 90.0,90.0, 21.0)]; [label setTag : indexPath.row]; label.text = [NSString stringWithFormat:@"%@",[arrImages objectAtIndex:indexPath.row]]; label.textColor = [UIColor redColor]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:12]; label.textColor = [UIColor colorWithRed:46.0/255.0 green:63.0/255.0 blue:81.0/255.0 alpha:1.0]; [cell.contentView addSubview:label]; return cell; […]

两个UICollectionViews和一个UIViewController中的两个UICollectionViewCells

我的故事板上有两个UICollectionView ,每个都有自己的插口: @IBOutlet weak var daysCollectionView: UICollectionView! @IBOutlet weak var hoursCollectionView: UICollectionView! 在每个集合视图中,我想使用不同types的单元格。 所以我创build了一个DayCell类和一个HourCell类。 然后在cellForItemAtIndexPath: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { if collectionView == self.dayCollectionView { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("dayCell", forIndexPath: indexPath) as DayCell … return cell } else if collectionView == self.hourCollectionView { let cell: HourCell = collectionView.dequeueReusableCellWithReuseIdentifier("hourCell", forIndexPath: indexPath) as […]

UICollectionView cell.ViewWithTag返回nil为UILabel

这个标签似乎返回零,即使我有正确的重用标识符和标签设置。 override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var identifier: String = "CollectionCell" var cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: indexPath) as! UICollectionViewCell // Configure the cell //save till later, when images are actually present //var cellItem1 = hostManager[indexPath.row * 2] let label:UILabel = cell.viewWithTag(1) as! UILabel return cell } 该程序打破了标签设置的位置= viewWithTag。 我没有为单元格设置自定义类,只是原型。 […]