views:

101

answers:

2

I have a custom UITableViewController subclass which I use in two places in a nib file. What should I do if I want the two instances to have slightly different behavior? Of course in the code I can select one kind of behavior or the other based on the value of a BOOL, but how do I set that BOOL from Interface Builder, without having to write an Interface Builder plugin?

A: 

Have two subclasses is probably easier, and will be easier to document.

AlBlue
+1  A: 

So far as I know, you can't set parameters in IB without writing an IB Plugin.

That said, you have two other options.

If it is as simple as a single BOOL, you're probably best off making it a property of the MyCustomViewController class and set it in code after you init:

customViewController = [[MyCustomViewController alloc]initWithNibName:@"CustomViewController" bundle:nil];
[customViewController setFunky:YES];

The other option is to create a protocol for a MyCustomViewDelegate. If you're not familiar with protocols, your header would look like this:

@class MyCustomViewController;

@protocol MyCustomViewDelegate
@required
-(BOOL)customViewShouldBeFunky:(MyCustomViewController*)customView;
@end

@interface MyCustomViewController : UIViewController {
  NSObject<MyCustomViewDelegate>  *delegate;
}
@property (readwrite, retain) IBOutlet NSObject<MyCustomViewDelegate> *delegate;
@end

Since it is an IBOutlet, you can wire up the delegate like any other delegate in Interface Builder.

Then call [delegate customViewShouldBeFunky:self] when you need to determine how your view should behave.

John Franklin