国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 托克逊县| 榆树市| 凤山市| 无极县| 福安市| 台安县| 西华县| 新泰市| 贵港市| 永泰县| 贵州省| 黑山县| 阿瓦提县| 澄城县| 庄浪县| 荆州市| 青田县| 旅游| 南康市| 温泉县| 分宜县| 江都市| 麻城市| 桂东县| 赤水市| 巴楚县| 雷山县| 云梦县| 翼城县| 乌拉特前旗| 平利县| 若尔盖县| 洞头县| 庄浪县| 沧州市| 始兴县| 蕲春县| 霍林郭勒市| 屏东市| 嘉义市| 应用必备|