DatePicker 之类

//DatePicker

- (IBAction)buttonPressed {
NSDate *selected = [datePicker date];
NSString *message = [[NSString alloc] initWithFormat:

@"The date and time you selected is: %@", selected];UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"Date and Time Selected"message:message

delegate:nilcancelButtonTitle:@"Yes, I did."otherButtonTitles:nil];

[alert show];} 


//single component

@interface BIDSingleComponentPickerViewController : UIViewController

<UIPickerViewDelegate, UIPickerViewDataSource>

@property (strong, nonatomic) IBOutlet UIPickerView *singlePicker;@property (strong, nonatomic) NSArray *pickerData;
- (IBAction)buttonPressed;

@end   //先声明协议和outlet

//picker view 的delegate和sources都要连到file's owner

- (IBAction)buttonPressed {
NSInteger row = [singlePicker selectedRowInComponent:0];NSString *selected = [pickerData objectAtIndex:row];NSString *title = [[NSString alloc] initWithFormat:

@"You selected %@!", selected];

UIAlertView *alert =

[alert show];}    //显示数据

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional
NSArray *array = [[NSArray alloc] initWithObjects:@"Luke", @"Leia",

@"Han", @"Chewbacca", @"Artoo", @"Threepio", @"Lando", nil];self.pickerData = array;

//声明数据

#pragma mark -
#pragma mark Picker Data Source Methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {return 1;

}

- (NSInteger)pickerView:(UIPickerView *)pickerViewnumberOfRowsInComponent:(NSInteger)component {

return [pickerData count];}

#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView

titleForRow:(NSInteger)row

forComponent:(NSInteger)component {return [pickerData objectAtIndex:row];

 }  //覆写 协议的方法

//doublePicker

#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {

return 2;}

- (NSInteger)pickerView:(UIPickerView *)pickerViewnumberOfRowsInComponent:(NSInteger)component {

if (component == kBreadComponent)return [self.breadTypes count];

return [self.fillingTypes count];}

#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView

titleForRow:(NSInteger)rowforComponent:(NSInteger)component {

if (component == kBreadComponent)
return [self.breadTypes objectAtIndex:row];

return [self.fillingTypes objectAtIndex:row];}

@end

//dependentPicker

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

NSBundle *bundle = [NSBundle mainBundle];
NSURL *plistURL = [bundle URLForResource:@"statedictionary"

withExtension:@"plist"];NSDictionary *dictionary = [NSDictionary

dictionaryWithContentsOfURL:plistURL];

self.stateZips = dictionary;

NSArray *components = [self.stateZips allKeys];
NSArray *sorted = [components sortedArrayUsingSelector:

@selector(compare:)];self.states = sorted;

delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];

NSString *selectedState = [self.states objectAtIndex:0];NSArray *array = [stateZips objectForKey:selectedState];self.zips = array;

} //处理数据

#pragma mark -
#pragma mark Picker Data Source Methods

  • -  (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {

    return 2;}

  • -  (NSInteger)pickerView:(UIPickerView *)pickerViewnumberOfRowsInComponent:(NSInteger)component {

    if (component == kStateComponent)return [self.states count];

    return [self.zips count];}

    #pragma mark Picker Delegate Methods

    • -  (NSString *)pickerView:(UIPickerView *)pickerView

      titleForRow:(NSInteger)rowforComponent:(NSInteger)component {

      if (component == kStateComponent)
      return [self.states objectAtIndex:row];

      return [self.zips objectAtIndex:row];}

    • -  (void)pickerView:(UIPickerView *)pickerViewdidSelectRow:(NSInteger)row

      inComponent:(NSInteger)component {if (component == kStateComponent) {

      NSString *selectedState = [self.states objectAtIndex:row];NSArray *array = [stateZips objectForKey:selectedState];self.zips = array;
      [picker selectRow:0 inComponent:kZipComponent animated:YES];[picker reloadComponent:kZipComponent];

      }}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值