Basic UI Elements
This series is inspired by https://www.binpress.com/objective-c-building-app-basic-ui-elements/. For introduction and reasoning for the series, read the introduction.
You'll create a regular iOS app project. As you set up project options, make sure to choose Storyboard under the Interface options, and Objective-C as the language.
When the project loads, the file structure should resemble the image below. You will have to delete some files now and make some changes to the project settings.
- delete SceneDelegate.h and SceneDelegate.m
- in Info.plist, delete the 2 key entries under Application Scene Manifest
- in AppDelegate.m, comment out or remove the two methods under the mark pragma. These two methods contain code referencing the deleted scene delegate.
The View Controller
The rest of the article describes setting up a root view controller. We should already have a root view controller (ViewController.h/m).
This should already be "hooked up" for us. If you select Main.storyboard and highlight View Controller Scene in the hierarchy, and select the Identity Inspector (CMD+Option+4), ViewController should already be selected as the backing class.
This means you can add the controls directly to the Storyboard, and create the actions manually as the article states.
Note that if you add the code the article suggests in AppDelegate.m:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = UIColor.whiteColor; _viewController = [[ViewController alloc] init]; self.window.rootViewController = _viewController; [self.window makeKeyAndVisible];
You'll end up overriding the storyboard with this new instance of the ViewController (try this by changing the color from
redColor - you'll get an empty red view).
Build and run the app, and everything should work!
Get the source: https://github.com/elliotrodriguez/ios-objc-part-one/tree/main