Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was missing the basic structure for the view controller.</p> <p>Creating an UIWindow inside the viewController fixed the problem for me. </p> <p>Full Source code:</p> <p>Static library view controller file (VC.m):</p> <pre><code>#import "VC.h" @interface VC () @property (nonatomic, strong) UILabel *label; @property (nonatomic, strong) UIButton *button; @property (nonatomic, strong) UIView *window; @end @implementation VC - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // CREATE UIVIEW INSIDE VIEW CONTROLLER _window = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window.backgroundColor = [UIColor whiteColor]; // CREATE BUTTON TO CLOSE VIEW CONTROLLER AFTER IS SHOWN _button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [_button addTarget:self action:@selector(closeWindow:) forControlEvents:UIControlEventTouchDown]; [_button setTitle:@"Close View" forState:UIControlStateNormal]; _button.frame = CGRectMake(115.0f, 150.0f, 200.0f, 30.0f); // ADD BUTTON TO THE UIWINDOW [_window addSubview: _button]; // ADD UIWINDOW TO VIEW CONTROLLER [self.view addSubview: _window]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Close ViewController - (IBAction)closeWindow:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; } @end </code></pre> <p>After import the static library and headers to a new app you can invoke the view controller with an IBAction like this:</p> <pre><code>#import "VC.h" //header for viewcontroller code in static library ... -(IBAction)callVC:(id)sender { VC *vc = [[VC alloc] init]; [self presentViewController:vc animated:YES completion:nil]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload