Question

is there away to initialise a view controller created in storyboards with a private property? For example, if I wasn't using storyboards I could do

DIViewController myViewController = [[DFViewController alloc] initWithObject:myObject];

myObject would be set as a private property declared in the DFViewController implementation file.

Thanks in advance.

Was it helpful?

Solution

I'm afraid there's no easy way to call your custom initializer with parameters. As a workaround, expose that property as public or add another public method to set the object, then feed it in prepareForSegue: sender:.

OTHER TIPS

As the others have said, you can't use a custom initializer from a storyboard or XIB file.

However, there are a variety of ways to set custom properties.

One that many people don't know about is to use "User Defined Runtime Attributes" in IB, select your view controller object, bring up the "Identity Inspector", and look for the section titled User Defined Runtime Attributes. You can add key/value pairs there that will be set in the selected object as it is loaded, including custom properties. (Although IB only allows you to specify a small number of data types like boolean, number, string, size, rect, range, color, and nil.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top