您的位置:首页 > 产品设计 > UI/UE

关于tableView样式为UITableViewStyleGrouped间距的设置

2014-07-08 09:34 585 查看
tableView的Grouped样式,是在每个section之间有固定的高度,像系统的设置界面

- (void)viewDidLoad
{
[super viewDidLoad];

_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 320, 460) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];

_dataArray1 = @[@"海贼王",@"火影忍者"];
_dataArray2 = @[@"穿越火线",@"DOTA2"];
}

#pragma mark - tableViewDelegate

//如果不设置section的高度是有默认的值
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//	return 12;//如果设置section的header高度,不设置footer高度,footer默认等于header高度
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//	return 12;//这个方法不写,或者return 0跟return 12的效果一样
//  return 0.01;//把高度设置很小,效果可以看成footer的高度等于0
//}
#pragma mark - tableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0)
{
return _dataArray1.count;
}
return _dataArray2.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"Cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if(indexPath.section == 0)
{
cell.textLabel.text = _dataArray1[indexPath.row];
}
else
{
cell.textLabel.text = _dataArray2[indexPath.row];
}
return cell;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: