国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

UIpickerView的使用

2019-11-09 17:36:44
字體:
供稿:網(wǎng)友

UipickerView類似于UItableView,使用方法非常相似; 自定義MJPickerView,繼承自UIpickerView;遵守兩個協(xié)議:UIPickerDataSource和UIPickerDelegate;設(shè)置數(shù)據(jù)源和代理;

1、兩個數(shù)據(jù)源方法

1、此方法返回的是列數(shù) - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2;} 2、此方法返回的是每一列的行數(shù) - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{if (component == 0) { return _listOne.count;} return _listTwo.count; }

2、代理方法:

1、設(shè)置每列寬度 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {if (self.listTwo) { if (component == 1) { return [UIScreen mainScreen].bounds.size.width - 120; } return 120;}return [UIScreen mainScreen].bounds.size.width;}2、設(shè)置每一列的每一行的顯示數(shù)據(jù),如果不實(shí)現(xiàn)這個代理方法,效果如下圖所示:-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{if (component == 0) { return [_listOne objectAtIndex:row];} else { return [_listTwo objectAtIndex:row]; }} 3、獲取選中的行列,得到數(shù)組中的數(shù)據(jù)- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{if (component == 0) { _selectedStrFromOneList = [_listOne objectAtIndex:row];} else { _selectedStrFromTwoList = [_listTwo objectAtIndex:row];}}

沒有實(shí)現(xiàn)titileForRow這個代理方法的效果:

沒有實(shí)現(xiàn)titileForRow這個代理方法的效果

3、設(shè)置為UITextField的inputView

self.cellTextFld.inputView = self.pickerV;

4、自定義toolBar,設(shè)置為UITextField的inputaccessoryView

UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(resignFirResponder)]; //占位用 UIBarButtonItem *selectItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"確定" style:UIBarButtonItemStyleDone target:self action:@selector(complete)];UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; [toolBar setItems:@[cancelItem,selectItem,doneItem]]; self.cellTextFld.inputAccessoryView = toolBar;

剩下的數(shù)據(jù)傳遞了,就非常簡單了;


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌鲁木齐县| 乳源| 永顺县| 星座| 建宁县| 绍兴市| 贡嘎县| 云和县| 永靖县| 阜新市| 醴陵市| 祁连县| 永德县| 会宁县| 玉树县| 新龙县| 望城县| 饶阳县| 白银市| 南京市| 民勤县| 临安市| 六盘水市| 邵武市| 修文县| 金湖县| 乌鲁木齐县| 梨树县| 留坝县| 红河县| 久治县| 蕉岭县| 清新县| 萍乡市| 青神县| 泌阳县| 临夏县| 宝清县| 郁南县| 凤山县| 太仆寺旗|