One more question about this approach...

On Jun 26, 2009, at 9:08 PM, mmalc Crawford wrote:

In the cell's nib file:
The class of the File's Owner should be your table view controller class.
        Set an identifier for the cell.
        Connect the appropriate outlet from File's Owner to the cell
        Connect the button's action to the File's Owner
        Connect the cell's button outlet to the button

Does the first line mean that I cannot reuse the XIB-based cells in different view controllers?

I currently have several custom cells (code only) that are used in 3 different view controllers. The approach I am using is a combination of the Apple-provided sample 'TouchCells' and this post: http://weblog.bignerdranch.com/?p=56

It looks like this:

if (cell == nil)
{
cell = (MyCustomCell *)[[[MyCustomCell alloc] initWithFrame:CGRectZero
      reuseIdentifier:MyCustomCellIdentifier] autorelease];
   [[cell checkButton] addTarget:self
      action:@selector(buttonPressed:)
      forControlEvents:UIControlEventTouchUpInside];
}

...where checkButton is a UIButton property of the custom cell. (and I am aware that I need to update my initWithFrame: method). This exact code works equally well in all 3 view controllers.

This is serving me well so far, though now that I am past my "I avoid IB for iPhone development" phase, I'm interested in reworking my cells around IB. But, if that means I have to have 3 copies of the same file just so that File's Owner can be different, I'm losing interest. Is there a way to use this technique and share the cells with multiple view controllers?

This might be more of a general question regarding XIB reuse. At the moment, I have a handful of XIB files for view controllers that are identical except for File's Owner. It would be nice to get away with using a single file.

Thanks,

Brian
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to