UIViewController *theController = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil];
[self.navigationController presentModalViewController:theController animated:TRUE];
Here's my code for showing my view. I know I can use app delegate variables, but it would be neater is I could pass a parameter in somehow, ideally using an enum. Is this possible?
To pass a function as a parameter into another function in Swift, the accepted parameter type needs to describe a function. Now you can call this function by passing it an argument that is any function that takes two doubles and returns a double. This is the quick answer.
While UIKit uses an event-driven framework, SwiftUI is based on a data-driven framework. In SwiftUI, views are a function of state, not a sequence of events (WWDC 2019). A view is bound to some data (or state) as a source of truth, and automatically updates whenever the state changes.
Parameters can provide default values to simplify function calls and can be passed as in-out parameters, which modify a passed variable once the function has completed its execution. Every function in Swift has a type, consisting of the function's parameter types and return type.
Just create a new init method for your HelpViewController and then call its super init method from there...
In HelpViewController.h
typedef enum
{
PAGE1,
PAGE2,
PAGE3
} HelpPage;
@interface HelpViewController
{
HelpPage helpPage;
// ... other ivars
}
// ... other functions and properties
- (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle onPage:(HelpPage)page;
@end
In HelpViewController.m
- (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)nibBundle onPage:(HelpPage)page
{
self = [super initWithNibName:nibName bundle:nibBundle];
if(self == nil)
{
return nil;
}
// Initialise help page
helpPage = page;
// ... and/or do other things that depend on the value of page
return self;
}
And to call it:
UIViewController *theController = [[HelpViewController alloc] initWithNibName:@"HelpView" bundle:nil onPage:PAGE1];
[self.navigationController presentModalViewController:theController animated:YES];
[theController release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With