On Sep 4, 2013, at 4:13 AM, cocoa-dev-requ...@lists.apple.com wrote:

> Date: Wed, 04 Sep 2013 10:23:04 +0100
> From: Dave <d...@looktowindward.com>
> Subject: Subclassing a View Controller in a Storyboard
> 
> Hi All,
> 
> If I am using a Storyboard that contains a view controller, 
> LTWMusicViewController that I'd like to sub-class like so:
> 
> LTWRockMusicViewController : LTWMusicViewController
> 
> Then in the viewDidLoad method, do:
> 
> -(void) viewDidLoad
> {
> [super viewDidLoad];
> 
> self.pMusicCategory = kRockMusicCategory;
> }
> 
> 
> ----------------------------
> 
> At present LTWMusicViewController is loaded using:
> 
> myViewController = [self.storyboard 
> instantiateViewController:@"LTWMusicViewController"];
> 
> 
> I want LTWRockMusicViewController to use same NIB etc, as 
> LTWMusicViewController, but just pre-set the self.pMusicCategory property to 
> Rock.
> 
> How do I do this using a Storyboard? I don't really want to copy all the 
> controls for LTWMusicViewController into LTWMusicViewController.

What you're doing has a lot of bad smells:

* If I'm only going to call instantiateViewController, why am I using a 
storyboard here at all? If I use a .xib file instead, I can tell the view 
controller what .xib to use at its view nib, regardless of it's class.

* If the only difference between this object and that one is 
self.pMusicCategory, why am I bothering to subclass? Why not set the music 
category of the instance as soon as it is created? Gosh, if I weren't using a 
storyboard, I could even have a designated initializer that takes a music 
category as a parameter.

* Even if you must use a storyboard, you can set an arbitrary variable in the 
resulting instance, using the user-defined runtime attributes.

* If all else fails, implement loadView. Now finding the view is up to you. You 
can keep the view in a .xib file even if you are getting the view controller 
from a storyboard (delete the view controller's view from the storyboard to 
indicate that you will supply it in some other way).

m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to