You are on page 1of 18

Lab 3 - iOS

Topics in Mobile Computing

Prepared by Y.H. KWOK


Wednesday, 26 September, 12

Task - Simple Vendor Machine



Create A New iOS Single View Project You are going to create a vendor machine app contains three UIViewController managed by UINavigationController

VC1 - Index page VC2 - List all stocking page VC3 - Page let people to buy

Project Name: TMCLab2A_iOS Package Name: com.tmc.ios.lab2a

Wednesday, 26 September, 12

Wednesday, 26 September, 12

Task1 Q1 - create navigation controller


To Create a navigation controller, you have to go to the AppDelegate.m Create a Navigation Collection to encapsulate ViewController

Wednesday, 26 September, 12

Task1 Q2 -set a global variable (out of scope)


Create a global variable (C language property) at any out of the class Can share value between diff objects Go to appDelegate.h

Wednesday, 26 September, 12

Task2

Create 2 Custom View Controllers:

1. BuyViewController 2. ListViewController

Wednesday, 26 September, 12

Task2

Create 2 Custom View Controllers:

Wednesday, 26 September, 12

Task3 - Q1

Complete the UI for ViewController

Wednesday, 26 September, 12

Task3 - Q2

Import BuyViewController.h and ListViewController.h

#import BuyViewController.h #import ListViewController.h

Add method to ViewContoller.h -(IBAction)buyZeroClicked:(id)sender -(IBAction)buyChunLoClicked:(id)sender -(IBAction)buyPepsiClicked:(id)sender -(IBAction)buyWaterClicked:(id)sender -(IBAction)listAll:(id)sender

Wednesday, 26 September, 12

Task3 - Q2

Complete method to ViewContoller.m Ask Navigation Controller to push to the new buy/list view controller
Sample: -(IBAction)buyZeroClicked:(id)sender { BuyViewController *buyVC = [[BuyViewController alloc]initWithNibName:@BuyViewController bundle:nil]; [buyVC setDrinkType:0]; //will do this later [self.navigationController pushViewController:buyVC animated:YES]; } Sample: -(IBAction)listAll:(id)sender { ListViewController *listVC = [[ListViewController alloc]initWithNibName:@ListViewController bundle:nil]; [self.navigationController pushViewController:listVC animated:YES]; }
Wednesday, 26 September, 12

Task4 - Q1

Complete the UI for ListViewController

Wednesday, 26 September, 12

Task4 - Q2

At ListViewController.h Import AppDelegate.h

#import appDelegate.h

Add dataled to ListViewController.h IBOutlet UILabel *labelZero, *labelChunLo, *labelPepsi, *labelWater;

Add method to ListViewContoller.h -(IBAction)rellBtnClicked:(id)sender;

Wednesday, 26 September, 12

Task4 - Q2

Complete method to ListViewContoller.m


- (void)viewDidLoad { [super viewDidLoad]; //show the display for all label; [labelZero setText:[NSString } -(IBAction) {

stringWithFormat:@%d, numZero];

rellBtnClicked:(id)sender

//set all drink to 100; //show the display for all label; }

Wednesday, 26 September, 12

Task5 - Q1

Complete the UI for BuyViewController

Wednesday, 26 September, 12

Task5 - Q2

At BuyViewController.h Import AppDelegate.h

#import appDelegate.h

Add dataled to BuyViewController.h IBOutlet UILabel *resultLabel, *buyLabel; IBOutlet UISlider *theSlider; int drinkType;

Add method to BuyViewContoller.h -(IBAction)buyBtnClicked:(id)sender -(void)setDrinkType:(int)i

Wednesday, 26 September, 12

Task5 - Q3

Complete method to BuyViewContoller.m


Sample: -(void)setDrinkType:(int)type { drinkType = type; if(type == 0) //show something related to Zero; else if(type==1) //show something related to ChunLo;

Wednesday, 26 September, 12

Task5 - Q3

Complete method to BuyViewContoller.m


Sample:

-(IBAction)buyBtnClicked:(id)sender
if(drinkType == 0) if(numZero > 0) numZero -= [mySlider value]; //update the UI else //show sold out }

Wednesday, 26 September, 12

Submission

Do it at home zip 3pngs + 1 zip le into 1 le

41308_3A_ChanTaiMan_iOS_Lab3

Upload the le to ftp://www.invivointeractive.com/ user: ive413083a or ive413083b or ive413083c pwd: tmc2012!

Save to /ios/lab3 folder

Wednesday, 26 September, 12