• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Odd Top Level Objects Issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Odd Top Level Objects Issue


  • Subject: Odd Top Level Objects Issue
  • From: Jonathan Dann <email@hidden>
  • Date: Fri, 16 Jan 2009 19:16:46 +0100

Hi Guys,

Some background:

I've recently written a class to manage the loading of UITableViewCells (or subclasses thereof) from nib. The idea is that a UITableViewController will have a concrete subclass of CellController and will pass off the cell creation and configuration tasks.

So the concrete CellController subclass (MyCustomCellController) recieves the -tableView:cellForRowAtIndexPath: message and first attempts to dequeue the cell from the table view, if unsuccessful it calls -[CellController cell] and then proceeds to configure the cell.

In -cell, the cell controller acquires a reference to the top level objects in the nib and returns the UITableViewCell instance. The idea being that the nib file only contains the cell (and of course the File's Owner and the First Responder). For example:

NSArray *topLevelObjects = [self.nibBundle loadNibNamed:self.nibName owner:self options:nil];
// raise if [topLevelObjects count] == 0 or > 1
return [topLevelObjects objectAtIndex:0];


The problem:

The issue here is that, after working for a long time, the topLevelObjects array has begun to return 2 objects. One is the custom cell and the other is a plain NSObject. Even rolling back my code to a previously working revision is no longer working (much to my surprise and annoyance).

Getting the malloc_history for the object shows the following trace:

Call [2] [arg=16]: thread_a0254720 |0x1 | start | main | UIApplicationMain | -[UIApplication _run] | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __NSFireDelayedPerform | -[UIApplication _runWithURL:] | - [UIApplication _loadMainNibFile] | -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:] | -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:] | +[NSObject alloc] | +[NSObject allocWithZone:] | _internal_class_createInstance | _internal_class_createInstanceFromZone | calloc | malloc_zone_calloc

Which tells me that NSBundle or UINib is creating a good-old NSObject and keeping it around for some reason. Even more odd is that the same object is returned when loading the top level objects from different nibs owned different concrete instances of my cell controller.

Inspecting, and rebuilding the main nib of my app, has not solved the problem. There's no plain NSObject created in any of my nibs.

Has anybody run into this one, its got me completely stumped. Of course I could work around it by iterating over the topLevelObjects array and returning the cell, but that is a little more fragile and I'd like to crash if I've genuinely done something wrong in my nib setup.

Thanks for any brainwaves you may have,

Jonathan

http://espresso-served-here.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Odd Top Level Objects Issue
      • From: Kevin Cathey <email@hidden>
  • Prev by Date: Re: object Properties released or autoreleased?
  • Next by Date: Re: Setting Xcode debugger to always show types?
  • Previous by thread: how to create a project template with XCode 3.1
  • Next by thread: Re: Odd Top Level Objects Issue
  • Index(es):
    • Date
    • Thread