UIDatePicker和UIPickerView实现生日选择、城市选择

效果:

1.控制器代码:

//
//  ViewController.m

#import "ViewController.h"
#import "Province.h"

@interface ViewController ()<UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>

@property (weak, nonatomic) IBOutlet UITextField *birthdayField;
@property (weak, nonatomic) IBOutlet UITextField *cityField;

@property(nonatomic,weak)UIDatePicker *datePicker;
@property(nonatomic,strong)NSMutableArray *provinces;

@property(nonatomic,weak)UIPickerView *pickerView;
@property(nonatomic,assign)NSInteger provinceIndex;

@end

@implementation ViewController

- (NSMutableArray *)provinces
{
    if (_provinces == nil) {
        _provinces = [NSMutableArray array];

        // 字典转模型
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"provinces" ofType:@"plist"];
        NSArray *data = [NSArray arrayWithContentsOfFile:filePath];

        for (NSDictionary *dict in data) {
            Province *p = [Province provinceWithDict:dict];

            [_provinces addObject:p];
        }
    }
    return _provinces;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 设置文本框的代理
    _birthdayField.delegate = self;
    _cityField.delegate = self;

    // 自定义键盘
    [self setupBirthdayKeyboard];
    // 自定义城市键盘
    [self setupCityKeyboard];
}

- (void)setupCityKeyboard
{
    // 创建UIPickerView
    UIPickerView *pickerView = [[UIPickerView alloc] init];
    pickerView.dataSource = self;
    pickerView.delegate = self;
    _pickerView = pickerView;

    //
    _cityField.inputView = pickerView;
}

#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0) { // 描述省
        return self.provinces.count;
    }else{ // 描述选中的省的城市
        Province *p = self.provinces[_provinceIndex];
        return p.cities.count;
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) { // 描述省
        Province *p = self.provinces[row];
        return p.name;
    }else{ // 描述城市
        Province *p = self.provinces[_provinceIndex];
        return p.cities[row];
    }
}

#pragma mark - UIPickerViewDelegate
/**
 *  用户主动滚动pickerView就会调用
 */
 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0) { // 滚动省份的时候,刷新城市
        // 记录当前选中的省份
        _provinceIndex = [pickerView selectedRowInComponent:0];

        // 刷新城市数据
        [pickerView reloadComponent:1];
    }

    // 给文本框赋值
    // 获取选中的省份
    Province *p = self.provinces[_provinceIndex];
    // 获取选中的城市
     NSInteger cityIndex = [pickerView selectedRowInComponent:1];
    NSString *cityName = p.cities[cityIndex];

    _cityField.text = [NSString stringWithFormat:@"%@ %@",p.name,cityName];
}

/**
 *  自定义生日键盘
 */
- (void)setupBirthdayKeyboard
{
    // 创建UIDatePicker
    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    _datePicker = datePicker;

    datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
    datePicker.datePickerMode = UIDatePickerModeDate;

    // 添加监听
    [datePicker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged];

    //
    _birthdayField.inputView = datePicker;
}

/**
 *  当UIDatePicker滚动的时候调用
 */
- (void)dateChange:(UIDatePicker *)datePicker
{
//    NSLog(@"%@",datePicker.date);
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString *dateStr = [fmt stringFromDate:datePicker.date];

    // 给生日文本框赋值
    _birthdayField.text = dateStr;
}

#pragma mark - UITextFieldDelegate

/**
 *  是否允许开始编辑
 */
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//{
//    return NO;
//}

/**
 *  文本框开始编辑的时候调用
 */
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == _birthdayField) { // 给生日文本框赋值

        [self dateChange:_datePicker];
    }else{ // 给城市文本框赋值
        [self pickerView:_pickerView didSelectRow:0 inComponent:0];
    }

}

/**
 *  是否允许用户输入文字
 */
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    return NO;
}

@end

2.Province模型

//
//  Province.h

#import <Foundation/Foundation.h>

@interface Province : NSObject

@property(nonatomic,strong)NSArray *cities;

@property(nonatomic,strong)NSString *name;

+ (instancetype)provinceWithDict:(NSDictionary *)dict;

@end
//
//  Province.m

#import "Province.h"

@implementation Province

+ (instancetype)provinceWithDict:(NSDictionary *)dict
{
    Province *p = [[self alloc] init];
    [p setValuesForKeysWithDictionary:dict];

    return p;
}

@end

3.省份城市数据plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>cities</key>
		<array>
			<string>福州</string>
			<string>龙岩</string>
			<string>南平</string>
			<string>宁德</string>
			<string>莆田</string>
			<string>泉州</string>
			<string>三明</string>
			<string>厦门</string>
			<string>永安</string>
			<string>漳州</string>
		</array>
		<key>name</key>
		<string>福建</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>济南</string>
			<string>滨州</string>
			<string>德州</string>
			<string>东营</string>
			<string>肥城</string>
			<string>海阳</string>
			<string>菏泽</string>
			<string>济宁</string>
			<string>莱芜</string>
			<string>莱阳</string>
			<string>聊城</string>
			<string>临沂</string>
			<string>平度</string>
			<string>青岛</string>
			<string>青州</string>
			<string>日照</string>
			<string>泰安</string>
			<string>威海</string>
			<string>潍坊</string>
			<string>烟台</string>
			<string>枣庄</string>
			<string>章丘</string>
			<string>淄博</string>
		</array>
		<key>name</key>
		<string>山东</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>成都</string>
			<string>阿坝</string>
			<string>巴中</string>
			<string>崇州</string>
			<string>达州</string>
			<string>大邑</string>
			<string>德阳</string>
			<string>都江堰</string>
			<string>峨眉山</string>
			<string>甘孜</string>
			<string>广安</string>
			<string>广元</string>
			<string>江油</string>
			<string>金堂</string>
			<string>乐山</string>
			<string>泸州</string>
			<string>眉山</string>
			<string>绵阳</string>
			<string>内江</string>
			<string>南充</string>
			<string>攀枝花</string>
			<string>遂宁</string>
			<string>西昌</string>
			<string>雅安</string>
			<string>宜宾</string>
			<string>资阳</string>
			<string>自贡</string>
		</array>
		<key>name</key>
		<string>四川</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>昆明</string>
			<string>保山</string>
			<string>楚雄</string>
			<string>大理</string>
			<string>德宏</string>
			<string>迪庆</string>
			<string>个旧</string>
			<string>丽江</string>
			<string>临沧</string>
			<string>怒江</string>
			<string>曲靖</string>
			<string>思茅</string>
			<string>文山</string>
			<string>西双版纳</string>
			<string>玉溪</string>
			<string>昭通</string>
		</array>
		<key>name</key>
		<string>云南</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>东城区</string>
			<string>西城区</string>
			<string>崇文区</string>
			<string>宣武区</string>
			<string>海淀区</string>
			<string>朝阳区</string>
			<string>丰台区</string>
			<string>石景山区</string>
			<string>通州区</string>
			<string>顺义区</string>
			<string>房山区</string>
			<string>大兴区</string>
			<string>昌平区</string>
			<string>怀柔区</string>
			<string>平谷区</string>
			<string>门头沟区</string>
			<string>密云县</string>
			<string>延庆县</string>
		</array>
		<key>name</key>
		<string>北京</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>石家庄</string>
			<string>保定</string>
			<string>泊头</string>
			<string>沧州</string>
			<string>承德</string>
			<string>邯郸</string>
			<string>河间</string>
			<string>衡水</string>
			<string>廊坊</string>
			<string>秦皇岛</string>
			<string>任丘</string>
			<string>唐山</string>
			<string>邢台</string>
			<string>张家口</string>
		</array>
		<key>name</key>
		<string>河北</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>南京</string>
			<string>常州</string>
			<string>高邮</string>
			<string>淮安</string>
			<string>连云港</string>
			<string>南通</string>
			<string>苏州</string>
			<string>宿迁</string>
			<string>太仓</string>
			<string>泰州</string>
			<string>无锡</string>
			<string>新沂</string>
			<string>徐州</string>
			<string>盐城</string>
			<string>扬州</string>
			<string>镇江</string>
		</array>
		<key>name</key>
		<string>江苏</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>台北</string>
			<string>高雄</string>
			<string>台南</string>
			<string>台中</string>
		</array>
		<key>name</key>
		<string>台湾</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>沈阳</string>
			<string>鞍山</string>
			<string>本溪</string>
			<string>朝阳</string>
			<string>大连</string>
			<string>丹东</string>
			<string>抚顺</string>
			<string>阜新</string>
			<string>葫芦岛</string>
			<string>锦州</string>
			<string>辽阳</string>
			<string>盘锦</string>
			<string>铁岭</string>
			<string>营口</string>
		</array>
		<key>name</key>
		<string>辽宁</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>长春</string>
			<string>白城</string>
			<string>白山</string>
			<string>珲春</string>
			<string>吉林</string>
			<string>辽源</string>
			<string>龙井</string>
			<string>舒兰</string>
			<string>四平</string>
			<string>松原</string>
			<string>通化</string>
			<string>延边</string>
		</array>
		<key>name</key>
		<string>吉林</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>呼和浩特</string>
			<string>阿拉善盟</string>
			<string>巴彦淖尔盟</string>
			<string>包头</string>
			<string>赤峰</string>
			<string>鄂尔多斯</string>
			<string>呼伦贝尔</string>
			<string>通辽</string>
			<string>乌海</string>
			<string>乌兰察布盟</string>
			<string>锡林郭勒盟</string>
			<string>兴安盟</string>
		</array>
		<key>name</key>
		<string>内蒙古</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>杭州</string>
			<string>北仑</string>
			<string>慈溪</string>
			<string>奉化</string>
			<string>湖州</string>
			<string>嘉兴</string>
			<string>金华</string>
			<string>丽水</string>
			<string>临海</string>
			<string>宁波</string>
			<string>宁海</string>
			<string>衢州</string>
			<string>三门</string>
			<string>绍兴</string>
			<string>台州</string>
			<string>天台</string>
			<string>温岭</string>
			<string>温州</string>
			<string>仙居</string>
			<string>象山</string>
			<string>义乌</string>
			<string>余姚</string>
			<string>舟山</string>
		</array>
		<key>name</key>
		<string>浙江</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>拉萨</string>
			<string>阿里</string>
			<string>昌都</string>
			<string>林芝</string>
			<string>那曲</string>
			<string>日喀则</string>
			<string>山南</string>
		</array>
		<key>name</key>
		<string>西藏</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>西宁</string>
			<string>果洛</string>
			<string>海北</string>
			<string>海东</string>
			<string>海南</string>
			<string>海西</string>
			<string>黄南</string>
			<string>玉树</string>
		</array>
		<key>name</key>
		<string>青海</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>澳门</string>
		</array>
		<key>name</key>
		<string>澳门</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>武汉</string>
			<string>鄂州</string>
			<string>恩施</string>
			<string>黄冈</string>
			<string>黄石</string>
			<string>荆门</string>
			<string>荆州</string>
			<string>潜江</string>
			<string>十堰</string>
			<string>随州</string>
			<string>天门</string>
			<string>仙桃</string>
			<string>咸宁</string>
			<string>襄樊</string>
			<string>孝感</string>
			<string>宜昌</string>
		</array>
		<key>name</key>
		<string>湖北</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>哈尔滨</string>
			<string>大庆</string>
			<string>大兴安岭</string>
			<string>鹤岗</string>
			<string>黑河</string>
			<string>虎林</string>
			<string>鸡西</string>
			<string>佳木斯</string>
			<string>密山</string>
			<string>牡丹江</string>
			<string>宁安</string>
			<string>七台河</string>
			<string>齐齐哈尔</string>
			<string>双鸭山</string>
			<string>绥化</string>
			<string>五常</string>
			<string>伊春</string>
		</array>
		<key>name</key>
		<string>黑龙江</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>南宁</string>
			<string>百色</string>
			<string>北海</string>
			<string>北流</string>
			<string>崇左</string>
			<string>防城港</string>
			<string>贵港</string>
			<string>桂林</string>
			<string>桂平</string>
			<string>河池</string>
			<string>贺州</string>
			<string>来宾</string>
			<string>柳州</string>
			<string>钦州</string>
			<string>梧州</string>
			<string>宜州</string>
			<string>玉林</string>
		</array>
		<key>name</key>
		<string>广西</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>郑州</string>
			<string>安阳</string>
			<string>鹤壁</string>
			<string>济源</string>
			<string>焦作</string>
			<string>开封</string>
			<string>洛阳</string>
			<string>漯河</string>
			<string>南阳</string>
			<string>平顶山</string>
			<string>濮阳</string>
			<string>三门峡</string>
			<string>商丘</string>
			<string>新乡</string>
			<string>信阳</string>
			<string>许昌</string>
			<string>周口</string>
			<string>驻马店</string>
		</array>
		<key>name</key>
		<string>河南</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>太原</string>
			<string>长治</string>
			<string>大同</string>
			<string>晋城</string>
			<string>晋中</string>
			<string>临汾</string>
			<string>吕梁</string>
			<string>朔州</string>
			<string>忻州</string>
			<string>阳泉</string>
			<string>运城</string>
		</array>
		<key>name</key>
		<string>山西</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>重庆</string>
		</array>
		<key>name</key>
		<string>重庆</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>南昌</string>
			<string>抚州</string>
			<string>赣州</string>
			<string>吉安</string>
			<string>景德镇</string>
			<string>九江</string>
			<string>萍乡</string>
			<string>上饶</string>
			<string>新余</string>
			<string>宜春</string>
			<string>鹰潭</string>
		</array>
		<key>name</key>
		<string>江西</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>天津</string>
		</array>
		<key>name</key>
		<string>天津</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>银川</string>
			<string>固原</string>
			<string>石嘴山</string>
			<string>吴忠</string>
			<string>中卫</string>
		</array>
		<key>name</key>
		<string>宁夏</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>西安</string>
			<string>安康</string>
			<string>宝鸡</string>
			<string>汉中</string>
			<string>商洛</string>
			<string>铜川</string>
			<string>渭南</string>
			<string>咸阳</string>
			<string>兴平</string>
			<string>延安</string>
			<string>榆林</string>
		</array>
		<key>name</key>
		<string>陕西</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>上海</string>
		</array>
		<key>name</key>
		<string>上海</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>香港</string>
		</array>
		<key>name</key>
		<string>香港</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>广州</string>
			<string>潮州</string>
			<string>从化</string>
			<string>东莞</string>
			<string>佛山</string>
			<string>河源</string>
			<string>鹤山</string>
			<string>化州</string>
			<string>惠州</string>
			<string>江门</string>
			<string>揭阳</string>
			<string>茂名</string>
			<string>梅州</string>
			<string>清远</string>
			<string>汕头</string>
			<string>汕尾</string>
			<string>韶关</string>
			<string>深圳</string>
			<string>阳江</string>
			<string>云浮</string>
			<string>湛江</string>
			<string>肇庆</string>
			<string>中山</string>
			<string>珠海</string>
		</array>
		<key>name</key>
		<string>广东</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>兰州</string>
			<string>白银</string>
			<string>定西</string>
			<string>甘南</string>
			<string>嘉峪关</string>
			<string>酒泉</string>
			<string>临夏</string>
			<string>陇南</string>
			<string>平凉</string>
			<string>庆阳</string>
			<string>天水</string>
			<string>武威</string>
			<string>张掖</string>
		</array>
		<key>name</key>
		<string>甘肃</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>贵阳</string>
			<string>安顺</string>
			<string>毕节</string>
			<string>都匀</string>
			<string>凯里</string>
			<string>六盘水</string>
			<string>铜仁</string>
			<string>兴义</string>
			<string>遵义</string>
		</array>
		<key>name</key>
		<string>贵州</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>乌鲁木齐</string>
			<string>阿克苏</string>
			<string>阿拉尔</string>
			<string>阿图什</string>
			<string>博乐</string>
			<string>昌吉</string>
			<string>哈密</string>
			<string>和田</string>
			<string>喀什</string>
			<string>克拉玛依</string>
			<string>库尔勒</string>
			<string>石河子</string>
			<string>图木舒克</string>
			<string>吐鲁番</string>
			<string>五家渠</string>
			<string>伊宁</string>
		</array>
		<key>name</key>
		<string>新疆</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>长沙</string>
			<string>常德</string>
			<string>郴州</string>
			<string>衡阳</string>
			<string>怀化</string>
			<string>吉首</string>
			<string>耒阳</string>
			<string>冷水江</string>
			<string>娄底</string>
			<string>韶山</string>
			<string>邵阳</string>
			<string>湘潭</string>
			<string>湘乡</string>
			<string>益阳</string>
			<string>永州</string>
			<string>岳阳</string>
			<string>张家界</string>
			<string>株州</string>
		</array>
		<key>name</key>
		<string>湖南</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>合肥</string>
			<string>安庆</string>
			<string>蚌埠</string>
			<string>亳州</string>
			<string>巢湖</string>
			<string>池州</string>
			<string>滁州</string>
			<string>阜阳</string>
			<string>淮北</string>
			<string>淮南</string>
			<string>黄山</string>
			<string>黄山景区</string>
			<string>九华山景区</string>
			<string>六安</string>
			<string>马鞍山</string>
			<string>青阳</string>
			<string>宿州</string>
			<string>铜陵</string>
			<string>芜湖</string>
			<string>宣城</string>
		</array>
		<key>name</key>
		<string>安徽</string>
	</dict>
	<dict>
		<key>cities</key>
		<array>
			<string>海口</string>
			<string>儋州</string>
			<string>东方</string>
			<string>琼海</string>
			<string>三亚</string>
			<string>万宁</string>
			<string>文昌</string>
			<string>五指山</string>
		</array>
		<key>name</key>
		<string>海南</string>
	</dict>
</array>
</plist>

时间: 2024-11-20 15:18:27

UIDatePicker和UIPickerView实现生日选择、城市选择的相关文章

UIPickerView简单应用——省份/城市选择实现

UIPickerView的简单应用--省份/城市选择的实现 实现效果如图,左边为省份选择,右边选择省份对应的城市 数据plist形式如图 工程下载地址:工程下载 https://github.com/Nongchaozhe/UIPickerView-Province-city UIPickerView的实现重要还是两个代理协议中方法的实现 - (void)viewDidLoad { [super viewDidLoad]; [self loadData]; _pickView = [[UIPic

UIPickerView的简单应用——省份/城市选择的实现

UIPickerView的简单应用--省份/城市选择的实现 实现效果如图,左边为省份选择,右边选择省份对应的城市 数据plist形式如图 工程下载地址:工程下载 https://github.com/Nongchaozhe/UIPickerView-Province-city UIPickerView的实现重要还是两个代理协议中方法的实现 - (void)viewDidLoad { [super viewDidLoad]; [self loadData]; _pickView = [[UIPic

UIPickerView城市选择

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">我使用UIPickerView写了一个城市选择器,可是我发现在省份滚轮滚动的时候如果同时再滚动城市滚轮会崩溃,代码如下:</span><pre name="code" class="objc">@interface GLVi

服务端如何做国内外选择城市功能

选择只是用户的行为,而服务端需要做好城市的储存,搜索. 国内城市选择效果: 首先只考虑字段之间的关系. 范围是从大到小的:省份--城市--地区 外键关系:一个省份 -- 多个城市:一个城市--多个地区 如何储存: 1. 省份,城市,地区各为一个字段,放在用户的 model 中 2. 只储存最小的.最具体的地点.比如地区.通过地区与其他字段的关系,获取其他字段的值. 国外城市的选择 各个国家的行政地区会存在差异.所以如果要兼容国内国外,就不能使用上面的行政关系. 那么,可以怎么做? 我想在想到的是

类似于铁道部12306的城市选择框的实现

第一次写,有点小紧张... 这两天研究铁道部的余票查询系统,参考网上大牛们的经典案例,也有了一些自己的心得,写在自己程序猿的道路上记录一下,也和大家一起分享,写的不好莫怪,大牛可以自动过滤,非喜勿喷,谢谢~ 今天先简单的介绍一下城市选择框的实现,与12306官网有一点差距,上图,先看看效果:      如图所示,支持拼音首字母查询,全拼音查询,汉字查询等 好了,现在谈一谈我是怎么实现的 首先是准备工作: 我们需要把城市的信息存入我们的数据库中,城市数据来源:https://kyfw.12306.

仿拉手团购App2--当前城市选择Activity

首页中点击城市TextView调转到当前城市选择Activity fragment_city.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background=&quo

美团HD(5)-选择城市

DJSelectCityViewController.m #import "DJSelectCityViewController.h" #import "DJConstantValue.h" #import "DJCityGroup.h" #import "MJExtension.h" @interface DJSelectCityViewController ()<UITableViewDataSource,UITab

1.选择城市

项目介绍 应用截图 主要功能 写的一个APP总结一下 使用车联网api解析天气数据并展示在界面 定位 通知栏 桌面小部件 动态添加删除城市并显示在界面上方便查看 选择城市界面 首先我网上找了个城市json数据信息,然后自己做了个json数据存放在res的raw目录下 然后需要解析出来存放在数据库中,不用每次都去解析json CoolWeatherOpenHelper public class CoolWeatherOpenHelper extends SQLiteOpenHelper { /**

Android练习——Spinner二级联动_城市选择

样式部分xml 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5