日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

IOS开发高级之点餐系统的实现-01

發布時間:2023/12/18 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发高级之点餐系统的实现-01 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS開發高級之點餐系統的實現-01


// // ViewController.m // 01-點餐系統 // // Created by 魯軍 on 2021/2/11. //#import "ViewController.h"@interface ViewController () <UIPickerViewDataSource,UIPickerViewDelegate>@property(nonatomic,strong)NSArray *foods;@property (weak, nonatomic) IBOutlet UILabel *lblFruit;@property (weak, nonatomic) IBOutlet UILabel *lblMainFood;@property (weak, nonatomic) IBOutlet UILabel *lblBar;- (IBAction)randomBtn:(id)sender;@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;@end@implementation ViewController- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{NSString *selFood = self.foods[component][row];NSLog(@"%@",selFood);switch (component) {case 0:_lblFruit.text = selFood;break;case 1:_lblMainFood.text = selFood;break;case 2:_lblBar.text = selFood;break;}}- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{NSArray *comFoods = self.foods[component];NSString *food = comFoods[row];return food;}- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{return self.foods.count;}- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{return [self.foods[component] count];}- (NSArray *)foods{if(_foods==nil){_foods = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"foods.plist" ofType:nil]];}return _foods;}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.for(int i =0;i<self.foods.count;i++){[self pickerView:self.pickerView didSelectRow:0 inComponent:i];}}- (IBAction)randomBtn:(id)sender {for(int i =0; i<self.foods.count;i++){NSUInteger count = [self.foods[i] count];u_int32_t radNum =arc4random_uniform((int)count);NSInteger selRowNum = [self.pickerView selectedRowInComponent:i];while (selRowNum ==radNum) {radNum=arc4random_uniform((int)count);}[self.pickerView selectRow:radNum inComponent:i animated:YES];[self pickerView:self.pickerView didSelectRow:radNum inComponent:i];}} @end

總結

以上是生活随笔為你收集整理的IOS开发高级之点餐系统的实现-01的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。