Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nib must contain exactly one top level object which must be a UITableViewCell instance

I got intermitent error when try to use nib that was registered for reuse. Im using the same custom cell on two ViewControllers.

2013-09-05 11:04:08.476 xxx[51395:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (TweetTableViewCellId) - nib must contain exactly one top level object which must be a UITableViewCell instance'

  1. Im use NIB file with one view at Object list - on top, sure -. It has type TweetViewCell, it that extends UITableViewCell -.
  2. I already define [b]identifier[/b] as "TweetTableViewCellId"
  3. Im load nib and did register it on viewDidLoad (i already debug and nib object aways is loaded)
  4. I try to recover registered cell using the same id.

some piece of code

// First Controller to use custom Cell
@implementation TweetsViewController

- (void) viewDidLoad
{
...
  UINib *nib =  [UINib nibWithNibName:kTweetTableViewCellNibName bundle:nil];
  [self.tweetsTableView registerNib:nib forCellReuseIdentifier:@"TweetTableViewCellId"];

..
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  TweetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTweetTableViewCellId forIndexPath:indexPath];
...
}

@end

// second Controller to use custom Cell

@implementation OfflineEpisodeModalViewController

- (void) viewDidLoad
{
  UINib *nib =  [UINib nibWithNibName:kTweetTableViewCellNibName bundle:nil];
  [self.tweetSearchTableView registerNib:nib forCellReuseIdentifier:kTweetTableViewCellId];
}

...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  TweetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TweetTableViewCellId" forIndexPath:indexPath];
}

@end

any suggestion?

like image 867
seufagner Avatar asked Sep 05 '13 14:09

seufagner


2 Answers

I had a label that was not under the "content view" in XIB file elements list on left hand side.

I removed that label and it worked.

like image 179
Imran Avatar answered Nov 06 '22 08:11

Imran


RESOLVED

Is simple, but anyway, is valid as a new knowledge: if you declare a xib file with the same name (my mistake), the file that will be loaded isnt guaranteed.

I delete the "forgotten" xib file and works!

like image 37
seufagner Avatar answered Nov 06 '22 06:11

seufagner