I'm currently having the constructor of my UIViewController defined like this:
public MyViewController(int mode) : base ("MyViewController", null)
{
//Initialize viewcontroller
}
I want to use different nib files under different circumstances based on the mode
parameter. The problem is I can't run any code in the constructor before calling the base constructor.
I know it's possible to use the [condition] ? [true_path] : [false_path]
[condition] ? [true_path] : [false_path]
syntax to pick between two nib strings, but I have to pick between four of them.
Is there any way to do this without resorting to adding new parameters to the MyViewController
constructor?
You could use a static method to solve this problem.
Define it like this:
private static string GetNibFile(int mode)
{
//Pick your nib file here, using a switch or something
return "ChosenNibName";
}
Then use it like this:
public MyViewController(int mode) : base (GetNibFile(mode), null)
{
//Initialize viewcontroller
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.