chapter 4 ios development
DESCRIPTION
iOS development Objective-CTRANSCRIPT
![Page 1: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/1.jpg)
Views
Views are responsible for drawing content, handling mul7touch events, and managing the layout of any subviews.
![Page 2: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/2.jpg)
Views
Right click in the project.
![Page 3: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/3.jpg)
Views Under Cocoa Touch, select Objec7ve-‐C class
![Page 4: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/4.jpg)
Views
Type the filename of the view.
![Page 5: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/5.jpg)
Views
Choose the loca7on and click Create.
![Page 6: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/6.jpg)
Views
Three files will be created. A header file, method file, and an xib file for the user interface.
![Page 7: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/7.jpg)
Views
Go to the xib file. Drag a label object and rename it “This is the first screen.”
![Page 8: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/8.jpg)
Views
Referencing a View means choosing which among the views you would like to load first when you run the mobile app.
![Page 9: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/9.jpg)
Views
Go to ViewController header file
![Page 10: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/10.jpg)
Views
Import the name of the new view
![Page 11: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/11.jpg)
Views
Declare a pointer object for that view.
![Page 12: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/12.jpg)
Views
Set the property of that view.
![Page 13: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/13.jpg)
Views
Go to the ViewController’s method file.
![Page 14: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/14.jpg)
Views
Synthesize the view object.
![Page 15: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/15.jpg)
Views
Instan7ate the view object by typing the code below.
![Page 16: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/16.jpg)
Views
Call the view.
![Page 17: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/17.jpg)
Views
Sending a message from the default view going to another view is also important.
![Page 18: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/18.jpg)
Views
In this example, we will be crea7ng a new Project.
![Page 19: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/19.jpg)
Views
Select Empty Applica7on and click Next.
![Page 20: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/20.jpg)
Views
Type in the Project Name
![Page 21: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/21.jpg)
Views
Select Desktop loca7on and click Create.
![Page 22: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/22.jpg)
Views
Since this is an empty template, the content of your Project will just be..
![Page 23: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/23.jpg)
Views
Create a new file.
![Page 24: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/24.jpg)
Views
Select Objec7ve-‐C class from Cocoa Touch
![Page 25: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/25.jpg)
Views
Name the file “FirstWindow”
![Page 26: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/26.jpg)
Views
Select the default loca7on.
![Page 27: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/27.jpg)
Views
Three files will be added to the Project Navigator
![Page 28: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/28.jpg)
Views
Go to AppDelegate.h File and import the name of your FirstWindow.
![Page 29: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/29.jpg)
Views
Declare the First View and set its property.
![Page 30: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/30.jpg)
Views
Go to AppDelegate.m file and look for the didFinishLaunching… method.
![Page 31: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/31.jpg)
Views
Comment this part And replace it with
![Page 32: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/32.jpg)
Views
Drag a texUield and a buVon object. Label the buVon “Send”.
![Page 33: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/33.jpg)
Views
Go to the header file and declare the texUield and the buVon objects.
![Page 34: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/34.jpg)
Views
Set their proper7es as well.
![Page 35: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/35.jpg)
Views
Declare a method with a return value from an event that will be triggered. The parameter should be the id of the buVon object.
![Page 36: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/36.jpg)
Views
Press on ctrl key, click Files Owner and drag the arrow to the texUield object. Point the id to the texUield id.
![Page 37: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/37.jpg)
Views
Do the same for the buVon.
![Page 38: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/38.jpg)
Views
Click on the buVon and click on Connec7ons Inspector. Select Touch Up Inside. Click on it and drag it to the Files Owner. Select the method event.
![Page 39: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/39.jpg)
Views
![Page 40: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/40.jpg)
Views
Create another ViewController named “Second Window”. Add a Label component on it and ini7alize it. Set its property as well.
![Page 41: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/41.jpg)
Views
![Page 42: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/42.jpg)
Views
![Page 43: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/43.jpg)
Views
Go to FirstWindow.m file and import SecondWindow.
![Page 44: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/44.jpg)
Views
Go to the method file of the FirstWindow and instan7ate the SecondWindow.
![Page 45: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/45.jpg)
Views
This code will slide the first window and show the second window
![Page 46: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/46.jpg)
Views
Send the String value from the texUield going to the Label object in the SecondWindow
![Page 47: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/47.jpg)
Views
Run the app.
![Page 48: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/48.jpg)
The Background
SeWng the color. Go to the method file of the View. Look for the viewDidLoad method. Type the syntax.
![Page 49: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/49.jpg)
The Background
![Page 50: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/50.jpg)
The Background
Image PaVern in a Color object. Add a .png file resource or just drag it to your Suppor7ng Files directory.
![Page 51: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/51.jpg)
The Background
![Page 52: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/52.jpg)
The Background
Type the syntax inside the viewDidLoad method.
![Page 53: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/53.jpg)
TableView
Displays a single-‐column list of mul7ple rows through which users can scroll. Each row in a table view is a UITableViewCell object.
![Page 54: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/54.jpg)
TableView
The plain style table view displays rows that occupy the full width of the view and can display op7onal headers and footers for arbitrary sec7ons of rows and for the table as a whole.
![Page 55: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/55.jpg)
TableView
The grouped style table view displays dis7nct groups of rows inset from the edges of the view and can display op7onal headers and footers between groups.
![Page 56: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/56.jpg)
TableView
Drag a TableView object in the work area.
![Page 57: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/57.jpg)
TableView
Go to the header file and inherit Delegate objects as parameters for the interface method.
![Page 58: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/58.jpg)
TableView
Declare the TableView object and set its property.
![Page 59: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/59.jpg)
TableView
In the method file of the view, synthesize the TableView
![Page 60: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/60.jpg)
TableView
In crea7ng a TableView, it is important to know how many sec7ons will be created in the table, how many rows per sec7on and what are the 7tles of every sec7on and row.
![Page 61: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/61.jpg)
TableView
Title of Every sec7on tableView 7tlefor…..
![Page 62: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/62.jpg)
TableView
Number of Rows per Sec7on
![Page 63: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/63.jpg)
TableView
Number of sec7ons in the table
![Page 64: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/64.jpg)
TableView
Here’s how to show some texts in every row in the table.
![Page 65: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/65.jpg)
TableView
In the xib file, control+click+drag File’s Owner to the TableView and select the tableview object.
![Page 66: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/66.jpg)
TableView
In the Connec7ons Inspector, look for Outlets and drag delegate and datasource to File’s Owner.
![Page 67: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/67.jpg)
TableView
Run the app and see the result.
![Page 68: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/68.jpg)
TableView
In iOS 7.0, to reload the Data in the TableView, an addi7onal code is required.
![Page 69: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/69.jpg)
TableView
Do this a]er reloading Data
![Page 70: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/70.jpg)
ImageView
This object displays an image in your workarea.
![Page 71: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/71.jpg)
ImageView
Drag an ImageView in the work area.
![Page 72: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/72.jpg)
ImageView
Go to the header file and declare an ImageView pointer
![Page 73: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/73.jpg)
ImageView
Set the property of the imageview
![Page 74: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/74.jpg)
ImageView
Go to the xib file and tag the imageview object.
![Page 75: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/75.jpg)
ImageView
We will be using this picture
![Page 76: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/76.jpg)
ImageView
All the pictures you want to use should be added as resources in the Suppor7ng Files directory.
![Page 77: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/77.jpg)
ImageView
You can just drag and drop a picture directly to this directory.
![Page 78: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/78.jpg)
ImageView
In the viewDidLoad method, call the picture by typing in this code
![Page 79: chapter 4 IOS Development](https://reader033.vdocuments.site/reader033/viewer/2022051223/577cc2c11a28aba71194839b/html5/thumbnails/79.jpg)
ImageView
Run the app.