Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:41:51+00:00 2026-06-11T18:41:51+00:00

I recently started playing with the awesome UICollectionView API, making reasonable progress, but have

  • 0

I recently started playing with the awesome UICollectionView API, making reasonable progress, but have been stuck for almost all day with an issue I’m hoping someone can help me with:

I need to add some custom details to certain cells’ attributes.
In order to do this, the right approach seem to be to subclass UICollectionViewLayoutAttributes and add the properties I need to my subclass. So far so good, except that when I return my LayoutAttributesSubclass, I always get the, somehow obscure, following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'

Having tried to track this down for a while, I’m under the impression that the error is related to representedElementKind and representedElementCategory being nil in my subclass’s instance. But those properties are read only, so I can’t set those.
I’ve managed to somehow bypass the error by cheating, getting a regular UICollectionViewAttributes instance, then changing it to a LayoutAttributesSubclass using object_setClass, but this then raises a ton of other issues, plus seems rather shady to me.

In short, does anyone knows what the error above means, and how to correctly create/use UICollectionViewLayoutAttributes subclasses?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:41:52+00:00Added an answer on June 11, 2026 at 6:41 pm

    When setting up custom attributes, you need to subclass UICollectionViewLayoutAttributes and subclass UICollectionViewLayout and “declare” your custom attribute subclass class name by overriding +(Class)layoutAttributesClass in your UICollectionViewLayout class. The system calls this class method to see if there is a custom class to be supplied when you use the factory method for instantiating/dequeuing layout attribute objects.

    @interface YourCustomCollectionViewAttributes : UICollectionViewLayoutAttributes
    
    @property (nonatomic)               UIEdgeInsets        myCustomProperty                        
    
    @end
    
    @interface YourCustomCollectionViewLayout : UICollectionViewLayout
    
    @end
    
    @implementation YourCustomCollectionViewLayout
    
    + (Class)layoutAttributesClass
    {
        return [IRTableCollectionViewLayoutAttributes class];
    }
    
    @end
    

    This is correct according to the documentation and should prevent the particular error you are having. Also when you implement custom iVars, be sure to implement an override for -(id)copyWithZone: or the UICollectionView will lose any custom values you have applied to your custom collection view object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have started playing with jQuery, and have been following a couple of
I have been playing a bit with Node.js. I recently started toying with Express
I have started playing around with Apache camel recently. So being the experimental type
I've recently been playing with allot of JavaScript and started to consider that I
I have recently started playing around with sites and created a basic page. <apex:page
I have recently started playing around with iOS development and have got most of
I've recently started playing around with the Microsoft Visual Studio Team System Profiler. All
I recently just started learning .NET, and more specifically I've been playing around with
I recently started playing with C#, but I am finding it very frustrating. It
I've recently been learning python and I just started playing with networking using python's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.