假设我有一个带两个部分的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
}
}
请发布您已有的代码! – 2012-04-26 19:56:00