有时候需要用到城市列表,作为地址选择,所以写了个demo。
核心代码:
#pragma mark - 获取城市数据
-(void)getCityData
{
NSString *path=[[NSBundle mainBundle] pathForResource:@"citydict"
ofType:@"plist"];
self.cities = [NSMutableDictionary dictionaryWithContentsOfFile:path];
[self.keys addObjectsFromArray:[[self.cities allKeys] sortedArrayUsingSelector:@selector(compare:)]];
//添加热门城市
NSString *strHot = @"热";
[self.keys insertObject:strHot atIndex:0];
[self.cities setObject:_arrayHotCity forKey:strHot];
}
#pragma mark - tableView
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20.0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];