Tag: uicollectionview

使UICollectionView即使在未满时也能滚动

当视图中没有足够的单元格时,UICollectionView默认禁用滚动function。 当发生这种情况时,我需要它拉回时的位置。 我知道一个黑客,我可以填充UICollectionView与空表,以启用滚动,但我希望会有一个稍微更stream畅的例子 我不想让视图滚动,而是自动弹回到原来的位置。 这是因为我已经在下面实现的效果。 有没有一种方法来实现这一点,当UICollectionView没有足够的单元格滚动被禁用。

在集合视图中为UI开关编写事件

嗨,我正试图编写UI集合视图中的UI切换和UI分段控制的事件。 我在collection视图单元格中声明了UIswitch和UIsegmentation控件。 @interface CollectionViewCell:UICollectionViewCell @property (strong, nonatomic) IBOutlet UISegmentedControl *mySegmentedControl; @property (strong, nonatomic) IBOutlet UISwitch *Myswitch; 并从视图controller.m访问它 – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath]; if(cell.Myswitch.isOn) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"!Alert" message:@"Do you want to exit the application?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil]; [alert show]; } else { } } […]

UICollectionView和补充视图崩溃

我有一个UICollectioView工作正常。 有2种方法可以到达这个页面。 虽然应用程序。 点击推送通知。 除了一种情况,一切都很好。 如果用户正在聊天,然后他退出应用程序(主页button),然后他得到一个推送通知他按下,应用程序崩溃。 崩溃: 2015-09-25 10:28:15.140 Quest [298:16922] *声明失败 – [UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/ UIKit-3505.16 / UICollectionView.m:1519 2015-09-25 10:28:15.146任务[298:16922] *由于未捕获exception'NSInternalInconsistencyException',原因:'UICollectionView dataSource未设置'***终止应用程序调用堆栈:(0x1828b4f5c 0x1973b7f80 0x1828b4e2c 0x1837a3f3c 0x187f97a38 0x187e6ebd4 0x187e6fb54 0x187e69b88 0x187e0700c 0x18760df14 0x187608b20 0x1876089e0 0x18760807c 0x187607dd0 0x1880c0bd4 0x18286c48c 0x18286bdc4 0x182869d4c 0x182798dc0 0x18d8ec088 0x187e72f60 0x100215590 0x197be28b8)的libc ++ abi.dylib:与typesNSException的未捕获的exception终止 推送处理器中的代码: func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) […]

UICollectionView上的可重用性问题

我曾与UITableView工作,但我从来没有在我的应用程序中使用UICollectionView 。 所以我想以编程方式创buildUICollectionView 。 以下是我的代码: UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc] init]; _collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 43, self.view.frame.size.width, self.view.frame.size.height – 84) collectionViewLayout:layout]; [_collectionView setDataSource:self]; [_collectionView setDelegate:self]; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); layout.minimumInteritemSpacing = 5; [_collectionView setBackgroundColor:self.view.backgroundColor]; [self.view addSubview:_collectionView]; 委托和数据源方法。 #pragma mark – #pragma mark – UITableView Delegate Methods – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { […]

如何在UIContainerView中连接UICollectionViewController

我有一个应用程序,看起来像这样: ViewController是我放入3个容器视图控制器的父VC。 我为所有三个,顶部,中间和BottomContainerViewControllers分类UIViewController 。 这是我的问题。 我想BottomVC有一个UICollectionView滚动的UICollectionView 。 所以我添加了一个UICollectionView ,你可以看到(给它一个很好的绿色背景)。 但是我的问题是,我怎么把这个钩起来呢? 这是我的BottomContainerViewController.h: #import <UIKit/UIKit.h> @interface BottomContainerViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate> @property (nonatomic, retain) IBOutlet UICollectionView *collectionView; @end .m文件有以下方法: – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 但是当我运行它时,我得到: [UICollectionViewController loadView] loaded the "qcP-Hl-Txn-view-aJq-Dc-875" nib but didn't get a UICollectionView.' UICollectionViewsockets已连接。 还有什么可能是这个问题?

滚动视图中的iOS 7集合视图

我正在使用storyboard来开发一个UIScrollView中有一个UICollectionView的应用程序。 我已经在故事板和代码中设置了委托和dataSource源。 我把假的信息来validation应用程序的布局,但UICollectionView和UICollectionViewCell不以任何方式出现。 .M @implementation PerfilUsuarioViewController – (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"Perfil"; self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fundo@2X.png"]]; FotosHelper* fotoCasal = [[FotosHelper alloc]init]; //Tamanho da view que sera exibida self.scrollView.contentSize = CGSizeMake(310, 1160); //Tamanho da tela do aparelho self.scrollView.frame = CGRectMake(0, 0, 320, 568); [self preparaZPositionCamposDetalhesCasal]; [self dadosPessoaUm]; self.fotosCollectionView.delegate = self; self.fotosCollectionView.dataSource = self; […]

UICollectionView重新加载数据问题

我有使用UICollectionView重新加载数据的问题。 我有这个数组viewDidLoad填充UICollectionView. array = [[NSMutableArray alloc] init]; [array addObject:@"1"]; [array addObject:@"2"]; [array addObject:@"3"]; [array addObject:@"4"]; [array addObject:@"5"]; [array addObject:@"6"]; 和方法: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = @"Cell"; //cell = [[UICollectionViewCell alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; myCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 100, 20)]; [titleLabel setText:[array […]

如果将UICollectionViewCell子类的contentView.translatesAutoResizingMaskToConstraints设置为“false”?

TL; DR 当尝试通过自动布局来设置UICollectionViewCells的大小时,即使是一个简单的例子,也可以轻松获得自动布局警告。 我们是否应该设置contentView.translatesAutoResizingMaskToConstraints = false来摆脱它们? 我正在尝试创build一个UICollectionView 自定义自动布局单元格 。 在viewDidLoad中: let layout = UICollectionViewFlowLayout() layout.estimatedItemSize = CGSize(width: 10, height: 10) collectionView.collectionViewLayout = layout 我的细胞是非常基本的。 这是一个宽度和高度为75的单一蓝色视图,用于testing目的。 约束是通过将视图固定在所有4个边上的超视图来创build的,并给它一个高度和宽度。 class MyCell: UICollectionViewCell { override init(frame: CGRect) { view = UIView() super.init(frame: frame) view.backgroundColor = UIColor.blueColor() contentView.addSubview(view) installConstraints() } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") […]

如何解决这个CollectionView崩溃?

我的应用程序有两个CollectionViewController 。 在给定的时间只有一个可见。 我在故事板上创build了以下结构:两个容器视图在彼此之上。 每个容器视图都有一个embedded的CollectionViewController 。 特定容器视图的可见性决定了哪个collectionViewController可见。 这就是问题。 两个CollectionViewController并行地接收数据,但是iOS有一个bug,如果一个CollectionViewController尝试在不可见的时候使用performBatchUpdates执行一个插入操作,那么这个bug会导致应用程序崩溃。 试图阻止这一点,我已经在两个CollectionViewController上创build了一个BOOL标志,以便他们可以知道它们是否可见并执行或者不是performBatchUpdates 。 就像是: if (self.isThisCollectionViewVisible == NO) return; [self.collectionView performBatchUpdates:^{ // bla bla… perform insert,m remove… 这解决了部分问题。 但是,应用程序继续在以下情况下崩溃:如果我点击button切换到不可见的CollectionViewController ,使其在接收更新时可见。 我的意思是:让我们调用第一个CollectionViewController , B调用第二个。 A是可见的,而B在这一点上是不可见的。 B开始接收数据,并试图执行一个performBatchUpdates但因为它是不可见的,所以if (self.isThisCollectionViewVisible == NO) return; 阻止performBatchUpdates运行,什么是好的。 现在我让A看不见, B看得见。 此时,标志self.isThisCollectionViewVisible被设置为YES , performBatchUpdates使应用程序崩溃,并显示以下错误: *断言失败 – [CollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UICollectionView.m:4625 *终止应用程序由于未捕获的exception'NSInternalInconsistencyException ',原因是:'更新无效:部分0中的项目数目无效。更新之后现有部分中包含的项目数目(76)必须等于更新前部分中包含的项目数目(70),加上或减去从该部分插入或删除的项目数(插入5个,删除2个),加上或减去移入或移出该部分的项目数(移入0个,移出0个)。 我认为CollectionViewController实际上还没有准备好和更新,能够执行performBatchUpdates …这不是以前更新数据源,因为它正在更新的问题。 我可以做什么检查来防止这种情况发生? 注:我特别注意到这个崩溃有些奇怪的东西。 它说5个元素被插入,2个被删除,但实际上3个元素被插入,0个被删除,2个在发生崩溃时被改变。

Swift – 无法将types化的视图出列:带标识符的UICollectionElementKindCell

当试图加载UICollectionView时,我得到了这个错误信息。 2015-07-23 16:16:09.754 XXXXX [24780:465607] *由于未捕获的exception'NSInternalInconsistencyException',原因:'无法出队types视图:具有标识符CollectionViewCell的UICollectionElementKindCell – 必须注册一个nib或类为标识符或连接故事板中的原型单元格*第一次抛出调用堆栈: 我的代码 @IBOutlet var collectionView: UICollectionView! func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell cell.backgroundColor = UIColor.blackColor() cell.textLabel?.text = "\(indexPath.section):\(indexPath.row)" cell.imageView?.image = UIImage(named: "category") return cell } 我已经在故事板检查器中声明了CollectionViewCell ,但仍然出现错误消息。 请指教。 谢谢。