```objc
#pragma mark - 数据源,以下为@required的方法
// 返回pickerView有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
NSLog(@"numberOfComponentsInPickerView");
return 3;
}
// 返回第component列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSLog(@"numberOfRowsInComponent");
return 2;
}
#pragma mark - 代理
// 返回第component列的每一行的行高
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 80.0;
}
// 返回第component列第row行的标题
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(@"-----%zd",[pickerView selectedRowInComponent:component]);
NSLog(@"titleForRow");
return @"a";
}
// NSAttributedString富文本属性: 可以描述文字大小和颜色
//- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0)
// 总结:如果同时实现返回字符串和view的方法,返回UIView的优先级比较高
// 返回第component列第row行的View
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIView *vw = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
vw.backgroundColor = [UIColor redColor];
return vw;
}
// 选中第component第row的时候调用
// __func__: 返回当前方法在哪个类里面调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"%s---%ld-%ld",__func__,component,row);
NSLog(@"%zd",[pickerView selectedRowInComponent:component]);
}
@end
“`