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

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

UIpickerView的使用

2019-11-09 16:33:05
字體:
供稿:網(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ù),如果不實現(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];}}

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

沒有實現(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ā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 思南县| 阿城市| 南丹县| 澄江县| 任丘市| 上栗县| 犍为县| 朔州市| 通海县| 永靖县| 金溪县| 郸城县| 宜章县| 左云县| 沽源县| 清流县| 珠海市| 南澳县| 和顺县| 新晃| 嵩明县| 隆安县| 通河县| 虞城县| 竹北市| 安丘市| 肃南| 涡阳县| 文昌市| 县级市| 奉化市| 西林县| 镇巴县| 衡阳县| 邵阳县| 威宁| 开封县| 三都| 鹤岗市| 耿马| 荔波县|