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 1087847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:59:33+00:00 2026-05-16T22:59:33+00:00

I have something weird going on with using UINib, although I suspect the real

  • 0

I have something weird going on with using UINib, although I suspect the real problem may be buried elsewhere.

My app is using a tableview, the content for the cells has been prepared in Interface Builder due to their complexity. For new cells (as opposed to reused ones), the contents of the nib are instantiated using the UINib Class. Because there is only one nib used for all cells and to reduce the overhead from loading the file each time, I added an UINib as a property cellNib to my viewcontroller subclass which I load once in my implementation of viewDidLoad.

Now for the weird part. Everything is working fine, the tableview is populated with its data and all cells are set up with the contents of the nib as they should be. But as soon as i scroll the tableview, the application crashes.
The callstack gave this away: -[NSCFNumber instantiateWithOwner:options:]: unrecognized selector sent to instance
Obviously, the message to instantiate the contents from cellNib again has been sent to the wrong object. The object to which the message is being sent differs from time to time, so there is something random going on.

I don’t get it – why is it working about 10 times while loading the tableview, but not anymore when the tableview is being scrolled?

If I create a new instance of UINib each time (as seen in my code below), then everything is working just fine, scrolling included.

Where do I make a mistake? Is the pointer of my UINib property going awol? If so, why??

Here’s the code I’m using (I removed all the data loading and other stuff to make it easier to read):

@interface NTDPadViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

   NSManagedObjectContext *managedObjectContext;
   NSMutableArray *ntdArray;
   IBOutlet UITableView *ntdTableView;
   UINib *cellNib;

}

@property(nonatomic,retain) NSManagedObjectContext *managedObjectContext;
@property(nonatomic,retain) NSMutableArray *ntdArray;
@property(nonatomic,retain) UITableView *ntdTableView;
@property(nonatomic,retain) UINib *cellNib;

@end

The implementation:

@implementation NTDPadViewController

@synthesize managedObjectContext;
@synthesize ntdArray;
@synthesize ntdTableView;
@synthesize cellNib;

-(void)viewDidLoad {

   [super viewDidLoad];
   cellNib = [UINib nibWithNibName:@"NTDCell" bundle:nil];

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

       [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
       [cell setBackgroundColor:[UIColor clearColor]];

       // These two should work equally well. But they don't... of course I'm using only one at a time ;)
       // THIS WORKS:
       UINib *test = [UINib nibWithNibName:@"NTDCell" bundle:nil];
       NSArray *nibArray = [test instantiateWithOwner:self options:nil];

       // THIS DOESN'T WORK:
       NSArray *nibArray = [cellNib instantiateWithOwner:self options:nil];

       [[cell contentView] addSubview:[nibArray objectAtIndex:0]];

   }

   return cell;
}

Thanks alot!!

  • 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-05-16T22:59:33+00:00Added an answer on May 16, 2026 at 10:59 pm

    This line assigns an autoreleased instance to cellNib:

    cellNib = [UINib nibWithNibName:@"NTDCell" bundle:nil];
    

    This means that with the following line:

    NSArray *nibArray = [cellNib instantiateWithOwner:self options:nil];
    

    … cellNib is already deallocated when its associated autorelease pool was drained and using it will result in undefined behaviour.

    If you want cellNib to stay around take ownership of it, e.g. by using the declared property:

    self.cellNib = [UINib nibWithNibName:@"NTDCell" bundle:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an app using threading, and something weird is happening. I have these
Something weird is going on with my tableview when changing data. I have something
I have something weird going on here. I just finished a site for a
i have a real weird thing going on. I am trying to get the
I have something really weird going on in my project (Flash CS5.5 and AIR
I have something of a weird situation going on. I'm trying to build a
Something really weird is going on with my database. I am using PHP to
I have just found something very weird while developing a website. While trying to
This is a weird bug. I know it's something funky going on with my
Today I had something weird happen in my copy of Resharper 5. I have

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.