XCode:iPhone:Basic
lastmod 2021-03-31created 2021-03-315 edits
Basics of iPhone app development in XCode.
Info
How to add a button touch-down event in Version 12.4 (12D4e)
Creating a project
Select iOS > App.
Getting started with the storyboard
To place controls such as buttons on the storyboard, select View > Show Library from the menu. (Shortcut: Command + Shift + L)
Button
First, click the "Add Editor on Right" button at the top right of the editor to split the code pane and the storyboard pane.
Right-click the button control, left-click Send Events > Touch Down, and drag it into the class in ViewController.h to add an event.
Label
Right-click the label -> drag, or
in the right-click popup -> left-click Reference Outlets > New Referencing Outlet and drag it into the class in ViewController.h to add an object reference.
Final code
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)touchDown:(id)sender;
@end
ViewController.m:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)touchDown:(id)sender {
[self.label setText: @"MyLabel!"];
}
@end
Adding a library
Select the top-level project file, select the General tab, click the + button in the Frameworks, Libraries, and Embedded Content section, and select from the list.