두 섹션이있는 UITableView
이 있다고 가정합니다. 해당 섹션의 데이터 소스가 비어 있으면 "섹션 이름이 비어있는 자리 표시 자 셀을 표시하려고합니다."UITableView의 자리 표시 자 셀
어떻게하면됩니까?
코드
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 1)
{
return @"Section One";
}
if(section == 0)
{
return @"Section Two";
}
return @"";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1)
{
return self.sectionOne.count;
}
else
{
return self.sectionTwo.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *theSource =[[NSArray alloc] init];
if(indexPath.section == 1)
{
theSource = self.sectionOne;
}
else
{
theSource = self.sectionTwo;
}
// See if there's an existing cell we can reuse
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (cell == nil)
{
// No cell to reuse => create a new one
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
cell.backgroundView = [[UIImageView alloc] init];
// Continue creating cell
}
}
이미 가지고있는 코드를 게시하십시오! –