我正在做一个类似的视图查看联系人在Contacts.app,这意味着我有不同的领域不需要(第二个工作电话,第二封电子邮件等)不同部分(电话,电子邮件等)。不显示空的分组单元tableview
当某些字段是空的,我不想显示它们,当所有的字段下部分空,我不想显示该节。此外,有些单元对它们有操作,就像在电话号码单元上敲击时一样,它会调用显示的号码。目前,这些操作在didSelectRowAtIndexPath
中手动处理,具有基本ifs,具体取决于单元位置。
我不能找到一个很好的解决方案做了这一切......我尝试字典数组(每个单元),每个部分,但事情很快就乱了。另外,由于行的顺序绝不相同,我不能轻易地用if来处理基于单元位置的didSelectRowAtIndexPath
方法中的所有操作。
哦,我在引擎盖下使用核心数据。
任何人都必须做同样的事情,并愿意分享他的想法吗?
谢谢!使用indexPath区分风格和行为
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (indexPath.section == 0)
{
// Custom actions here
}
else if (indexPath.section == 1)
{
// Other actions here
[self showMailComposeWithEmail:cell.textLabel.text];
}
}
而另一种方法:
现在我的静态IFS设置的为例分化细胞
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (indexPath.section == 0)
{
if (indexPath.row == 0)
{
cell.textLabel.text = self.contact.phone;
}
}
else if (indexPath.section == 1)
{
if (indexPath.row == 0)
{
cell.textLabel.text = self.contact.email;
}
}
return cell;
}
你可以展示在其中添加数据的代码 – Dhara
你怎么从那里我添加数据意味着什么? – allaire
您是否将数据添加到数组或字典? – Dhara