UIPickerView控件學習總結

UIPickerView知識點總結

1 UIPickerView主要掌握其數據源跟代理方法。即實現它們的協議UIPickerViewDataSource,UIPickerViewDelegate

#pragma mark -PickerView的數據源方法
//告訴PickerView中有多少組,即有多少個滾輪。
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

//告訴PickerView中"對應的組"中的有多少行。
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

- #pragma mark -PickerView的代理方法
//告訴PickerView中每一組每一行顯示文字。
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

//當手指滑動PickerView時,PickerView會告訴我們 現在選擇的是 第幾組(component)第幾行(row)。
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

-#pragma mark 通常用於自定義pickerView的cellView
//參數:(UIView *)view代表的是 如果有可循環使用的View的話,會返回該View,若沒有則返回爲空。另外,該循環引用在iOS6中是沒有問題的,但是在iOS7中則有bug(蘋果官方承認的,但是不知道是否已經有修正)。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

-#pragma mark 設置pickerView裏每一個view的高度
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
#pragma mark 設置pickerView裏每一個view的寬度
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;

2 UIPickerView其他的一些常用的方法

//獲取選中行的行號
int row = [self.pickerView selectedRowInComponent:i];
//通過"代碼"的形式 設置(選中) 某一組某一行
[self.pickerView selectRow:randomRow inComponent:i animated:YES];
//刷新第i組的數據
[self.pickerView reloadComponent:i];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章