collectionview

How to insert Cell in UICollectionVIew Programmatically?

橙三吉。 提交于 2019-11-27 13:39:52
问题 I have a UICollectionView and it works fine, but I want to add a few UICollectionViewCells items programmatically into the collection view. So how can I achieve this? To further clarify: when I say programmatically I mean inserting a cell during runtime, when an action is fired, not when the app is loaded (using the viewDidLoad method). I know when the model is updated and the call is made to UICollectionView in the insertItemsAtIndexPaths: method. It should create a new cells, but it's not

Is force cast really bad and should always avoid it?

老子叫甜甜 提交于 2019-11-27 11:19:14
问题 I started to use swiftLint and noticed one of the best practices for Swift is to avoid force cast. However I used it a lot when handling tableView, collectionView for cells : let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID, forIndexPath: indexPath) as! MyOffersViewCell If this is not the best practice, what's the right way to handle this? I guess I can use if let with as?, but does that mean for else condition I will need to return an empty cell? Is that acceptable? if

How do you set the duration for UICollectionView Animations?

耗尽温柔 提交于 2019-11-27 09:36:46
问题 I have a custom flow layout which is adjusting the attributes for cells when they are being inserted and deleted from the CollectionView with the following two functions, but I'm unable to figure out how you would adjust the default animation duration. - (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath { UICollectionViewLayoutAttributes* attributes = [self layoutAttributesForItemAtIndexPath:itemIndexPath]; // Assign the new

Swift viewWillTransition not called

孤街醉人 提交于 2019-11-27 08:02:24
问题 I'm creating a full screen image gallery using a UICollectionView . When the user rotates the device, I perform updates to the UICollectionView within func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) I present this UIViewController modally and have a UICollectionView taking up the full screen. Within viewDidLoad , I create the flow layout as: let flowLayout = UICollectionViewFlowLayout() flowLayout.scrollDirection = .horizontal flowLayout

Multiple collectionView in a UIViewController - IOS swift

送分小仙女□ 提交于 2019-11-26 23:51:46
问题 I tried many days to realise this: I want to add in my UIViewController two different CollectionView. For example I want to put images in these collectionView Each CollectionView use its own images. Is this possible? I will be very happy if somebody can give me a hand. :) 回答1: This is possible, you just need to add each UICollectionView as a subview, and set the delegate and dataSource to your UIViewController. Here's a quick example. Assuming you have one UICollectionView working, you should

Enforce collectionView to have only 2 rows

浪尽此生 提交于 2019-11-26 21:55:51
问题 I have to make one collection view so that irrespective of iphone size we have just 2 images in each row and also we need border between each row and column as shown in the image. I want like this: 回答1: Try this code. Just a different approach. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout layout

Where do I get a thread-safe CollectionView?

心已入冬 提交于 2019-11-26 06:26:25
问题 When updating a collection of business objects on a background thread I get this error message: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread. Ok, that makes sense. But it also begs the question, what version of CollectionView does support multiple threads and how do I make my objects use it? 回答1: The following is an improvement on the implementation found by Jonathan. Firstly it runs each event handler on the