////VIEWCONTROLLER.M//Order ordering System////Created by Yaguangzhu on 15/8/27.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () <UIPickerViewDataSource,UIPickerViewDelegate>@property (nonatomic,strong) Nsarray*Foods, @property (weak, nonatomic) Iboutlet UILabel*Fruitlbl, @property (weak, nonatomic) Iboutlet UILabel*Meatlbl, @property (weak, nonatomic) Iboutlet UILabel*Waterlbl;-(ibaction) random; @property (weak, nonatomic) Iboutlet Uipickerview*Pickerview;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib. for(intComponent =0; Component < Self.foods.count; Component + +) {[Self Pickerview:nil didselectrow:0Incomponent:component]; }}-(Nsarray *) foods{if(_foods = =Nil) {_foods= [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] Pathforresource:@"Foods"OfType:@"plist"]]; } return_foods;}-(Nsinteger) Numberofcomponentsinpickerview: (Uipickerview *) pickerview{returnSelf.foods.count;}-(Nsinteger) Pickerview: (Uipickerview *) Pickerview numberofrowsincomponent: (nsinteger) component{//[Self.foods objectatindex:component]. return[Self.foods[component] count];}-(NSString *) Pickerview: (Uipickerview *) Pickerview Titleforrow: (nsinteger) Row forcomponent: (nsinteger) component{returnSelf.foods[component][row]; //return @ "haha";}- (void) Pickerview: (Uipickerview *) Pickerview Didselectrow: (nsinteger) Row incomponent: (nsinteger) component{if(Component = =0) {Self.fruitLbl.text=Self.foods[component][row]; }Else if(Component = =1) {Self.meatLbl.text=Self.foods[component][row]; }Else{Self.waterLbl.text=Self.foods[component][row]; } }- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(ibaction) Random { for(intComponent =0; Component < Self.foods.count; Component + +) { //the line number before removing intOldrow =[Self.pickerview selectedrowincomponent:component]; //make the current line number equal to the previous line number introw =Oldrow; intCount =[Self.foods[component] count]; while(Row = =Oldrow) { //Random line numberrow = Arc4random ()%count; } //Pickerview Select a row of a column by itself[Self.pickerview selectrow:row incomponent:component Animated:yes]; //assign a value to the label below[self Pickerview:nil didselectrow:row incomponent:component]; }}@end
ios-Ordering System