chapter 4 ios development

79
Views Views are responsible for drawing content, handling mul7touch events, and managing the layout of any subviews.

Upload: badongfapper

Post on 18-Jul-2016

222 views

Category:

Documents


2 download

DESCRIPTION

iOS development Objective-C

TRANSCRIPT

Page 1: chapter 4 IOS Development

Views  

Views  are  responsible  for  drawing  content,  handling  mul7touch  events,  and  managing  the  layout  of  any  subviews.  

Page 2: chapter 4 IOS Development

Views  

Right  click  in  the  project.  

Page 3: chapter 4 IOS Development

Views  Under  Cocoa  Touch,  select  Objec7ve-­‐C  class  

Page 4: chapter 4 IOS Development

Views  

Type  the  filename  of  the  view.  

Page 5: chapter 4 IOS Development

Views  

Choose  the  loca7on  and  click  Create.  

Page 6: chapter 4 IOS Development

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

Views  

Go  to  the  xib  file.  Drag  a  label  object  and  rename  it  “This  is  the  first  screen.”  

Page 8: chapter 4 IOS Development

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

Views  

Go  to  ViewController  header  file  

Page 10: chapter 4 IOS Development

Views  

Import  the  name  of  the  new  view  

Page 11: chapter 4 IOS Development

Views  

Declare  a  pointer  object  for  that  view.  

Page 12: chapter 4 IOS Development

Views  

Set  the  property  of  that  view.  

Page 13: chapter 4 IOS Development

Views  

Go  to  the  ViewController’s  method  file.  

Page 14: chapter 4 IOS Development

Views  

Synthesize  the  view  object.  

Page 15: chapter 4 IOS Development

Views  

Instan7ate  the  view  object  by  typing  the  code  below.  

Page 16: chapter 4 IOS Development

Views  

Call  the  view.  

Page 17: chapter 4 IOS Development

Views  

Sending  a  message  from  the  default  view  going  to  another  view  is  also  important.  

Page 18: chapter 4 IOS Development

Views  

In  this  example,  we  will  be  crea7ng  a  new  Project.  

Page 19: chapter 4 IOS Development

Views  

Select  Empty  Applica7on  and  click  Next.  

Page 20: chapter 4 IOS Development

Views  

Type  in  the  Project  Name  

Page 21: chapter 4 IOS Development

Views  

Select  Desktop  loca7on  and  click  Create.  

Page 22: chapter 4 IOS Development

Views  

Since  this  is  an  empty  template,  the  content  of  your  Project  will  just  be..  

Page 23: chapter 4 IOS Development

Views  

Create  a  new  file.  

Page 24: chapter 4 IOS Development

Views  

Select  Objec7ve-­‐C  class  from  Cocoa    Touch  

Page 25: chapter 4 IOS Development

Views  

Name  the  file  “FirstWindow”  

Page 26: chapter 4 IOS Development

Views  

Select  the  default  loca7on.  

Page 27: chapter 4 IOS Development

Views  

Three  files  will  be  added  to  the  Project  Navigator    

Page 28: chapter 4 IOS Development

Views  

Go  to  AppDelegate.h  File  and  import  the  name  of  your  FirstWindow.  

Page 29: chapter 4 IOS Development

Views  

Declare  the  First  View  and  set  its  property.  

Page 30: chapter 4 IOS Development

Views  

Go  to  AppDelegate.m  file  and  look  for  the  didFinishLaunching…  method.  

Page 31: chapter 4 IOS Development

Views  

Comment  this  part      And  replace  it  with  

Page 32: chapter 4 IOS Development

Views  

Drag  a  texUield  and  a  buVon  object.  Label  the  buVon  “Send”.  

Page 33: chapter 4 IOS Development

Views  

Go  to  the  header  file  and  declare  the  texUield  and  the  buVon  objects.  

Page 34: chapter 4 IOS Development

Views  

Set  their  proper7es  as  well.  

Page 35: chapter 4 IOS Development

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

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

Views  

Do  the  same  for  the  buVon.  

Page 38: chapter 4 IOS Development

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

Views  

Page 40: chapter 4 IOS Development

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

Views  

Page 42: chapter 4 IOS Development

Views  

Page 43: chapter 4 IOS Development

Views  

Go  to  FirstWindow.m  file  and  import  SecondWindow.  

Page 44: chapter 4 IOS Development

Views  

Go  to  the  method  file  of  the  FirstWindow  and  instan7ate  the  SecondWindow.  

Page 45: chapter 4 IOS Development

Views  

This  code  will  slide  the  first  window  and  show  the  second  window  

Page 46: chapter 4 IOS Development

Views  

Send  the  String  value  from  the  texUield  going  to  the  Label  object  in  the  SecondWindow  

Page 47: chapter 4 IOS Development

Views  

Run  the  app.  

Page 48: chapter 4 IOS Development

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

The  Background  

Page 50: chapter 4 IOS Development

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

The  Background  

Page 52: chapter 4 IOS Development

The  Background  

Type  the  syntax  inside  the  viewDidLoad  method.  

Page 53: chapter 4 IOS Development

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

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

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

TableView  

Drag  a  TableView  object  in  the  work  area.  

Page 57: chapter 4 IOS Development

TableView  

Go  to  the  header  file  and  inherit  Delegate  objects  as  parameters  for  the  interface  method.  

Page 58: chapter 4 IOS Development

TableView  

Declare  the  TableView  object  and  set  its  property.  

Page 59: chapter 4 IOS Development

TableView  

In  the  method  file  of  the  view,  synthesize  the  TableView  

Page 60: chapter 4 IOS Development

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

TableView  

Title  of  Every  sec7on        tableView        7tlefor…..  

Page 62: chapter 4 IOS Development

TableView  

Number  of  Rows  per  Sec7on  

Page 63: chapter 4 IOS Development

TableView  

Number  of  sec7ons  in  the  table  

Page 64: chapter 4 IOS Development

TableView  

Here’s  how  to  show  some  texts  in  every  row  in  the  table.  

Page 65: chapter 4 IOS Development

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

TableView  

In  the  Connec7ons  Inspector,  look  for  Outlets  and  drag  delegate  and  datasource  to  File’s  Owner.    

Page 67: chapter 4 IOS Development

TableView  

Run  the  app  and  see  the  result.  

Page 68: chapter 4 IOS Development

TableView  

In  iOS  7.0,  to  reload  the  Data  in  the  TableView,  an  addi7onal  code  is  required.  

Page 69: chapter 4 IOS Development

TableView  

Do  this  a]er  reloading  Data  

Page 70: chapter 4 IOS Development

ImageView  

This  object  displays  an  image  in  your  workarea.  

Page 71: chapter 4 IOS Development

ImageView  

Drag  an  ImageView  in  the  work  area.  

Page 72: chapter 4 IOS Development

ImageView  

Go  to    the  header  file  and  declare  an  ImageView  pointer  

Page 73: chapter 4 IOS Development

ImageView  

Set  the  property  of  the  imageview  

Page 74: chapter 4 IOS Development

ImageView  

Go  to    the  xib  file  and  tag  the  imageview  object.  

Page 75: chapter 4 IOS Development

ImageView  

We  will  be  using  this  picture  

Page 76: chapter 4 IOS Development

ImageView  

All  the  pictures  you  want  to  use  should  be  added  as  resources  in  the  Suppor7ng  Files  directory.      

Page 77: chapter 4 IOS Development

ImageView  

You  can  just  drag  and  drop  a  picture  directly  to  this  directory.  

Page 78: chapter 4 IOS Development

ImageView  

In  the  viewDidLoad  method,  call  the  picture  by  typing  in  this  code  

Page 79: chapter 4 IOS Development

ImageView  

Run  the  app.