25515

UICollectionViewCell Only Updates After Scrolling

Question:

I've got an issue with my UICollectionView where my cells are always initiated blank/in a default state with no data.

The data only appears in the cells after scrolling them in and out of view.

Thoughts? Thanks.

CODE:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"EquipmentCell"; APInventoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; if (!cell) cell = [[APInventoryCollectionViewCell alloc] init]; //set cell data... cell.label.text = [arrayOfStrings objectAtIndex:indexPath.row]; return cell; }

Answer1:

Your problem is that you probably set the arrayOfStrings somewhere in the viewDidLoad method of your view controller, the problem with that is that the collectionview datasource calls are done before that.

What you should do in your viewDidLoad method just call [collectionview reloadData]; an you will be fine

Recommend

  • IOS UICollectionView with ScrollView
  • CollectionView Highlights incorrect Cell When Scrolling
  • Use CollectionView methods from another swift file
  • How can I make an array that holds types?
  • Realm Object-Level Notifications inside UICollectionViewCell's
  • Design UIView subclass auto layout with custom size in Interface Builder xib file
  • UIViewControllerAnimatedTransitioning with Safe Area Insets on iPhone X
  • Abstract class in Swift
  • CSStickyHeaderFlowLayout swift
  • Messing UIButton in each UICollectionViewCell in Scrolling Filmstrip
  • how do I change an image by selecting a cell in CollectionView
  • How to select CollectionView cell in RxSwift
  • UIRefreshControl with low height UICollectionView
  • How to resolve docker host names (/etc/hosts) in containers
  • Best win32 compiled scripting language? [closed]
  • Timeout a query
  • Merge Module leaving files during uninstall
  • Adding a model to a Marionette CollectionView's collection doesn't trigger onItemAdd callb
  • HttpURLConnection.getOutputStream() takes 20 seconds. Why?
  • Problems to linebreak with an int in JLabel
  • Date difference with leap year
  • How would I use PHP exceptions to define a redirect?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Join two tables and save into third-sql
  • JSON with duplicate key names losing information when parsed
  • Display Images one by one with next and previous functionality
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Matplotlib draw Spline from multiple points
  • XCode can't find symbols for a specific iOS library/framework project
  • Calling of Constructors in a Java
  • Compare two NSDates in iPhone
  • Transpose CSV data with awk (pivot transformation)
  • Use group_by to filter specific cases while keeping NAs
  • log4net write single file for each call to log.info
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Converting MP3 duration time
  • java string with new operator and a literal