IOS中的各种Picker(2)
来源:未知 责任编辑:责任编辑 发表时间:2015-09-17 09:44 点击:次
p> [picker dismissViewControllerAnimated:YES completion:nil];
p>}
p>
p>
p>UIPickerView
p>
p>在Component较多的时候,PickerView稍微要复杂一些。首先初始化和设置属性
p>
p>[cpp]
p>- (void)pickerViewAndMethod
p>{
p> UIPickerView *pickerView = [[UIPickerView alloc] init];
p> pickerView.delegate = self;
p> pickerView.dataSource = self;
p> //显示选择活动器
p> pickerView.showsSelectionIndicator = YES;
p> _cityField.inputView = pickerView;
p> _cityField.text = @"北京 - 海淀";
p>}
p>
p>
p>实现数据源和代理方法,来刷新自身数据和界面。
p>
p>[cpp]
p>- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
p>{
p> return rComponentCount;
p>}
p>
p>- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
p>{
p> if (component == rProvinceComponent)
p> {
p> return _cityList.count;
p> }
p> else
p> {
p> NSInteger i = [pickerView selectedRowInComponent:rProvinceComponent];
p> NSArray *arr = _cityList[i][@"city"];
p> return arr.count;
p> }
p>}
p>
p>- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
p>{
p> if (component == rProvinceComponent)
p> {
p> NSString *proName = _cityList[row][@"province"];
p> return proName;
p> }
p> else
p> {
p> NSInteger i = [pickerView selectedRowInComponent:rProvinceComponent];
p> NSString *cityName = _cityList[i][@"city"][row];
p> return cityName;
p> }
p>}
p>
p>- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
p>{
p> [pickerView reloadComponent:rCityComponent];
p>
p> NSInteger proIndex = [pickerView selectedRowInComponent:rProvinceComponent];
p> NSString *proName = _cityList[proIndex][@"province"];
p>
p> NSInteger cityIndex = [pickerView selectedRowInComponent:rCityComponent];
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>