ITP 342 Mobile App Dev. Connections

Similar documents
ITP 342 Mobile App Dev. Connections

ITP 342 Mobile App Dev. Interface Builder in Xcode

My First iphone App. 1. Tutorial Overview

S A M P L E C H A P T E R

ITP 342 Mobile App Dev. Fundamentals

Mobile Development - Lab 2

A Mad Libs app that you will navigate through 3 UIViewControllers to add text that will be shown in a story on the fourth UIViewController.

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode

App. Chapter 19 App. App (ViewController) App. Single View Application Single View Application View. (View Controller)

My First iphone App (for Xcode version 6.4)

ios Core Data Example Application

ios Tic Tac Toe Game John Robinson at Rowan University

ios 9 SDK Development

ios DeCal : Lecture 2 Structure of ios Applications: MVC and Auto Layout

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

CSC 581: Mobile App Development Spring 2018

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

Working with Text, Keyboards, and Buttons

My First Cocoa Program

CSC 581: Mobile App Development Spring 2019

Building the App - Part 5 - Adding a Link

Document Version Date: 1st March, 2015

Gerontechnology II. Collecting Smart Phone Sensor Data for Gerontechnology. Using ios

ios Development - Xcode IDE

Registering for the Apple Developer Program

Apple Watch Docs. Release 0.1. Michael Hahn

ITP 342 Mobile App Dev. Delegates

ios Application Development Lecture 2: Seminar and Unit 1

Building Mapping Apps for ios With Swift

UI Design and Storyboarding

Gestures. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Structuring an App Copyright 2013 Apple Inc. All Rights Reserved.

Tip Calculator App Introducing Swift, Text Fields, Sliders, Outlets, Actions, View Controllers, Event Handling, NSDecimalNumber,

In the first class, you'll learn how to create a simple single-view app, following a 3-step process:

CS193P: HelloPoly Walkthrough

Mac OS X and ios operating systems. Lab 1 Introduction to Mac OS X and ios app development. Gdańsk 2015 Tomasz Idzi

IOS - TEXT FIELD. Use of Text Field. Important Properties of Text Field. Updating Properties in xib

Topics in Mobile Computing

Implementing UI Designs in Interface Builder

ITP 342 Mobile App Dev. Table Views

Types of Views. View category Purpose Examples of views. Display a particular type of content, such as an image or text.

Step 1: Open Xcode and select Create a new Xcode Project from the Welcome to Xcode menu.

ITP 342 Advanced Mobile App Dev. Memory

ITP 342 Mobile App Dev. Interface Fun

ITP 342 Mobile App Dev. Collection View

MVC & Onwards. CS 442: Mobile App Development Michael Saelee

Assignment III: Graphing Calculator

ITP 342 Mobile App Dev. Alerts

Stream iphone Sensor Data to Adafruit IO

S A M P L E C H A P T E R

Building Faster in Xcode

The MVC Design Pattern

ios Application Development Hello World App Rubric

ITP 342 Advanced Mobile App Dev. Core Data

iphone Application Tutorial

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

InterfaceBuilder and user interfaces

CSE 438: Mobile Application Development Lab 2: Virtual Pet App

Assignment III: Graphing Calculator

Learn to make ios apps

Mobile Computing. Overview. What is ios? 8/26/12. CSE 40814/60814 Fall 2012

Your First iphone Application

Tables. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Learn to make desktop LE

} override func didreceivememorywarning() { 26 super.didreceivememorywarning() 27 } 28 } Pause Stop

Mobile Development Lab 3

ITP 342 Mobile App Dev. Table Views

Chapter 2 Welcome App

Corrections and version notes

ios Developer s Guide Version 1.0

Learn to make watchosle

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

Your First iphone OS Application

Social Pinboard: ios(swift) Application

Introductory ios Development

Assignment I: Concentration

Cocoa Programming A Quick-Start Guide for Developers

ITP 342 Mobile App Dev. Interface Components

ADVANCED M A. Learn SiriKit, imessage apps, rich notifications, and more. with real-world projects HACKING WITH SWIFT COMPLETE TUTORIAL COURSE

Stanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015

Stanford CS193p. Developing Applications for ios. Fall CS193p. Fall

User Interfaces. Lecture 15. Application Programming on Mac OS. Hamza Bennani September 4, 2018

User Interfaces. Lecture 19. Cocoa: Mouse and Keyboard Events. Hamza Bennani September 18, 2018

CLEARVIEW KIT INSTALLATION GUIDE

lectures/2/src2/nib1/nib1/appdelegate.h // AppDelegate.h // Nib1 // David J. Malan // Harvard University //

Assignment I Walkthrough

COMPLETE TUTORIAL COURSE. Learn to make tvos LE. apps with real-worldam S F

Building GUIs with UIKit. Kevin Cathey

HACKING WITH SWIFT. Practical. ios 10 COMPLETE TUTORIAL COURSE. Learn to develop apps. for ios 10 by building MP. real-world projects E S

Collection Views Hands-On Challenges

ios Application Development Lecture 3: Unit 2

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

A Better MVC. 300 line view controllers or bust. Dave A guy who thinks too deeply about stuff

Mobile Application Development

Beginning Mac Programming

Miscellaneous Topics

Assignment II: Calculator Brain

Assignment III: Graphing Calculator

Lab - Working with ios

Developing Applications for ios

Transcription:

ITP 342 Mobile App Dev Connections

User Interface Interactions First project displayed information to the user, but there was no interaction. We want the users of our app to touch UI components such as buttons and have stuff happen. What happens when a text field is touched? The keyboard is displayed. The user can enter info. 2

User Interface Interactions What happens when a text field is touched? The keyboard is displayed. The user can enter info. The Swift class for that View Controller scene needs access to the UI component. How? 3

Connections We need to connect the UI components in Interface Builder with our Swift classes. We create IBOutlets and IBActions. 4

IBOutlets & IBActions Outlets Instance variables that are declared using the keyword IBOutlet A reference from code to an object in Interface Builder Any instance variable that you create and want to connect to an object in IB must be preceded by the IBOutlet keyword Create when you want to access or modify properties of an interface builder element Actions Methods that are part of your controller class and declared with the keyword IBAction Tells Interface Builder that this method is an action and can be triggered by a control A method you want a user interface object to be able to call Create when you want to respond to user interaction with an interface builder element 5

Example Label Text Field Button Label 6

Text Field Examples of IBOutlets When you want to get input from a text field in code Label When you want to update the label in code 7

IBOutlets From Interface Builder (storyboard file), click on the Assistant Editor For the right panel, select the class file (ViewController) Control drag from an element in IB to a line inside class Enter a name for the IBOutlet (ivar) and select weak 8

Property Attributes IBOutlets (Interface Builder components) Use weak // IBOutlets @IBOutlet weak var nametextfield: UITextField! @IBOutlet weak var messagelabel: UILabel! 9

IBOutlets Memory Allocation We are pointing to an object created by the storyboard Do not alloc & init those objects Use them to access and set info 10

Steps 1. Drag an object into Interface Builder 2. Connect the object with an outlet 3. Get and set the object's attributes and/or call methods on that object class USCViewController : UIViewController { @IBOutlet weak var messagelabel: UILabel! } @IBAction func buttontouched(_ sender: UIButton) { // There is an attribute named text on UILabel self.messagelabel.text = "Hello Trojan" } 11

Text Field A text field accepts a single line of user input (shown here with a purpose description and placeholder text). A text field is a fixed-height field with rounded corners. When users tap a text field, a keyboard appears. When users tap Return in the keyboard, the text field handles the input in an application-specific way. 12

13

Text Field Attributes Inspector Text - default value Placeholder - text that will be displayed in grey inside the text field when the field has no value Text Input Traits For Capitalize, select Words For Return Key, select Done When having the user enter a number For Keyboard under Text Input Traits, select Number Pad Setting these kinds of attributes can greatly improve the user s experience 14

IBOutlet for TextField Example of creating an IBOutlet for the TextField 15

IBOutlet Getting the Text Variable name such as nametextfield To get the values of the text fields, use the text property on the text field in the implementation file self.varname.text You may also get the length of the text self.varname.text.count 16

UITextField Apple Documentation https://developer.apple.com/library/ios/docum entation/uikit/referen ce/uitextfield_class/ 17

text Property The text property is of type String String also has properties and methods that we want to use i.e. count https://developer.apple.com/documentation/swift/ string 18

Example class ViewController : UIViewController { @IBOutlet weak var nametextfield: UITextField! @IBAction func buttontouched(_ sender: UIButton) { let name: String = self.nametextfield.text?? "" } if name.count > 0 { self.messagelabel.text = "Fight on, \(name)" } else { self.messagelabel.text = "Fight on!" } 19

UILabel Apple Documentation https://developer.apple.com/library/ios/docum entation/uikit/referen ce/uilabel_class/ 20

UILabel UILabel has a property named text Just like UITextField It s a String It allows us to change the text of the UILabel 21

IBOutlet for Label Example of creating an IBOutlet for the Label 22

IBOutlets Example of IBOutlets in the class file class ViewController : UIViewController { } @IBOutlet weak var nametextfield: UITextField! @IBOutlet weak var messagelabel: UILabel! 23

Button Example of IBActions When you want to execute code when the user touches the button 24

IBActions From Interface Builder (storyboard file), click on the Assistant Editor For the right panel, select the swift file (ViewController.swift) Control drag from an element in IB to a line inside the implementation file under class Enter a name for the IBAction (method) and select the event 25

IBActions for Button Example of creating an IBAction for the Button 26

IBActions for Button Example of IBAction in the implementation file Now need to implement the method class ViewController : UIViewController { } @IBAction func buttondidpressed(_ sender: UIButton) { // Fill in code to get text from TextField // Set the message Label } 27

Making the Keyboard Go Away When the user taps the Done button, a did end on exit event will be generated Need to add an action method to our controller class such as textfieldexit: The first responder is the control that the user is currently interacting with When a text field yields first responder status, the keyboard associated with it goes away When the user taps the Done button on the ios keyboard, the Did End on Exit event will fire Make a connection from that event to textfieldexit: action @IBAction func textfieldexit(_ sender: UITextField) { sender.resignfirstresponder() } 28

Touch Background When the user touches anything, but the text field, the keyboard needs to go away Multiple ways to make this happen 2 common ways: Background button Touch events Need to implement one of the two ways 29

Background Button Since the keyboard for the number text field doesn t have a Done button, we will create an invisible button Drag a Button to your view s window Resize it to fill the entire screen Put this button behind everything by selecting Editor Arrange Send to Back Change the button s Type to Custom Create a method called backgroundtouched: to have the text fields resign first responder Make a connection from the Touch Up Inside event to the new method @IBAction func textfieldexit(_ sender: UIButton) { self.nametextfield.resignfirstresponder() } 30

Touch Events The second mechanism for hiding the keyboard involves wiring up an event to be called when the user touches the background view of the screen (or any view other than the text field). To achieve this, we will implement the touchesbegan event handler method on the view controller. This method will need to check that the object being touched by the user is not the text field itself. The method will then simply call the resignfirstresponder method of the text field to hide the keyboard. 31

touchesbegan: func touchesbegan(_ touches: Set<UITouch>, with event: UIEvent?) { let touch = event!.alltouches?.first! if self.nametextfield.isfirstresponder && touch.view!= self.nametextfield{ self.nametextfield.resignfirstresponder() } } super.touchesbegan(touches, with: event) 32

Buttons Add 2 Buttons to the View Clear the text Display images (if you want to use images) IBActions Event Touch Up Inside Methods leftbuttontouched & rightbuttontouched (or you can use one method) 33

Note: Interface Builder Everything we do in Interface Builder can be done in code. The reverse is not true. 34

Helpful Hints To open documentation in Xcode, hold the option key and double click a keyword or method name To change the name of a variable or method (such as an IBOutlet or IBAction) Select the text Right click (control click) Select Refactor à Rename To correct the indentation Select the code Select Editor à Structure à Re-Indent To auto complete code, use the Tab key 35

Resources https://developer.apple.com/library/ios/docum entation/stringstextfonts/conceptual/textan dwebiphoneos/keyboardmanagement/keyb oardmanagement.html 36