国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 防城港市| 凤凰县| 禹州市| 长泰县| 洪雅县| 鸡泽县| 沁源县| 静乐县| 台中县| 遂平县| 温宿县| 扬州市| 南郑县| 卢湾区| 金溪县| 连平县| 庆城县| 太仓市| 桐柏县| 龙门县| 咸宁市| 琼海市| 德州市| 山西省| 多伦县| 红河县| 界首市| 绥棱县| 宜川县| 西吉县| 澄迈县| 澎湖县| 钦州市| 苏尼特右旗| 正镶白旗| 扎鲁特旗| 兴宁市| 商城县| 依安县| 沁源县| 德江县|