확인을 클릭합니다. 내 돈 들어
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
에서
해키 첫 번째이자 가장 복잡한 두 가지 옵션이 ... /가 두 번째 섹션과 cellForRowAtIndexPath
if (section == 0)
에있는 세포의 수를 반환 할 수는의 데이터를 넣어 보통의 방법으로 ... else
[theArray objectAtIndex:indexPath.section]
을 대신 사용하여 배열 밖으로 정보를 가져올 수 있습니다.
(훨씬 더 간단하고 더 나은 실천)에 ..있는 UITableViewCell 하위 클래스를 생성하고 설정할 수하는 .m 사용자 정의 셀에 너무
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
static NSString *MyCellIdentifier = @"MyCustomCell";
switch (indexPath.section) {
case 0:
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// setup your 1st section cells here
return cell;
}
default:
{
MYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if (!cell)
cell = [[MYTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];
// all other layout code here if indexPath.row == 0 etc.
return cell;
}
}
처럼 cellForRowAtIndexPath
에 그것을 사용
-(void)layoutSubviews
{
[super layoutSubviews];
self.imageView.frame = CGRectMake(0,0,0,0); // lay them out at the top/middle/wherever in your cell
self.textLabel.frame = CGRectMake(0,0,0,0); // which will allow for some space at the bottom/edges
}
이 방법을 사용하면 셀 자체에서 패딩을 설정할 수 있습니다.이 패딩은 더 깨끗하고 재사용이 가능합니다. 당신이 간격을 표시하기 위해 다른 색상을 원하는 경우에, 당신은 사용자 정의있는 UITableViewCell 하위 클래스 방법
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
에 UIViews를 만들어야하고 이미지/내용이있는 경우 [UIColor clearColor];
에 당신이 항상 셀의 backgroundColor
설정할 수 있습니다 [self.contentView addSubView:someView];
를 사용하여 추가 tableView 뒤
셀 또는 섹션 사이에 공백을 원하십니까? – Zigglzworth
세포 대신에 솜씨보기를 사용하십시오 –
벼룩의 대답을 참조하십시오 : http://stackoverflow.com/questions/6216839/how-to-add-spacing-between-uitableviewcell – Zigglzworth