码迷,mamicode.com
首页 > 其他好文 > 详细

UItableViewGroup

时间:2015-07-06 15:43:42      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

第一步

 tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, 480) style:UITableViewStyleGrouped];

第二步,设置各个分组的数据

 NSArray * gruop1 = @[@"北京"];
    [dataSourse addObject:gruop1];
    NSArray * gruop2 = @[@""];
    [dataSourse addObject:gruop2];
    NSArray * gruop3 = [NSMutableArray arrayWithObjects:@"北京",@"天津",@"上海",@"广州",@"石家庄",@"承德", nil];
    [dataSourse addObject:gruop3];
    NSArray * group4 = @[@"全部城市"];
    [dataSourse addObject:group4];
    self.automaticallyAdjustsScrollViewInsets = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];

第三步:返回分组数(方法为number开头)

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return dataSourse.count;
}

第四步:返回每个分组的标题

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"当前选中城市";
    }else if(section ==1)
        return @"GPS定位您所在的城市";
    else if ( section ==2)
        return @"热门城市";
    else
        return @"";
}

 第五步:给cell赋值
NSArray * array = dataSourse[indexPath.section];
    cell.textLabel.text = [array objectAtIndex:indexPath.row];

几个重要的协议方法

自定义
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

修改
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

 

UItableViewGroup

标签:

原文地址:http://www.cnblogs.com/huoxingdeguoguo/p/4624226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!