//
// UIPickerView.h
// UIKit
//
// Copyright (c) 2006-2013, Apple Inc. All rights reserved.
//
#pragma - mark 和tableview一样 需要实现数据源方法和代理方法
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UITableView.h>
#import <UIKit/UIKitDefines.h>
@protocol UIPickerViewDataSource, UIPickerViewDelegate;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIPickerView : UIView <NSCoding, UITableViewDataSource>
{
@private
NSMutableArray *_tables;
UIView *_topFrame;
NSMutableArray *_dividers;
NSMutableArray *_selectionBars;
id<UIPickerViewDataSource> _dataSource;
id<UIPickerViewDelegate> _delegate;
UIView *_backgroundView;
NSInteger _numberOfComponents;
UIImageView *_topGradient;
UIImageView *_bottomGradient;
UIView *_foregroundView;
CALayer *_maskGradientLayer;
UIView *_topLineView;
UIView *_bottomLineView;
@package
struct {
unsigned int needsLayout:1;
unsigned int delegateRespondsToNumberOfComponentsInPickerView:1;
unsigned int delegateRespondsToNumberOfRowsInComponent:1;
unsigned int delegateRespondsToDidSelectRow:1;
unsigned int delegateRespondsToViewForRow:1;
unsigned int delegateRespondsToTitleForRow:1;
unsigned int delegateRespondsToAttributedTitleForRow:1;
unsigned int delegateRespondsToWidthForComponent:1;
unsigned int delegateRespondsToRowHeightForComponent:1;
unsigned int showsSelectionBar:1;
unsigned int allowsMultipleSelection:1;
unsigned int allowSelectingCells:1;
unsigned int soundsDisabled:1;
unsigned int usesCheckedSelection:1;
unsigned int skipsBackground:1;
} _pickerViewFlags;
}
@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource; // default is nil. weak reference
@property(nonatomic,assign) id<UIPickerViewDelegate> delegate; // default is nil. weak reference
@property(nonatomic) BOOL showsSelectionIndicator; // default is NO
// info that was fetched and cached from the data source and delegate
@property(nonatomic,readonly) NSInteger numberOfComponents;
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
- (CGSize)rowSizeForComponent:(NSInteger)component;
// returns the view provided by the delegate via pickerView:viewForRow:forComponent:reusingView:
// or nil if the row/component is not visible or the delegate does not implement
// pickerView:viewForRow:forComponent:reusingView:
- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
- (void)reloadAllComponents; // 重新加载所有的列
- (void)reloadComponent:(NSInteger)component; // 重新刷新某一列
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated; // 自动选中某行某列
- (NSInteger)selectedRowInComponent:(NSInteger)component; // 返回选中的行号,需要传一个列号的参数
@end
@protocol UIPickerViewDataSource<NSObject>
@required
// 返回多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 返回每一列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
@end
@protocol UIPickerViewDelegate<NSObject>
@optional
// component列的宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
// component 列的行高
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
// 某一行某一列显示什么文字
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 返回每一行带有文字属性的标题
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0);
// 某一行显示的view控件(可重用)
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
// 选中某一列的某一行就会调用这个方法(每一次只有一个可以选,所以只有一个方法)
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
@end
UIPickerView.h
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 新爱莲说Hélène, je m'appelle Hélène/Hélène Rollès 蓍草填词/江北客@伏羲...
- objc-runtime.h 中代码: #include <objc/runtime.h> #include<ob...