iOS在Indexpath上的TableCell上添加标签

时间:2015-05-07 21:50:10

标签: ios objective-c uitableview uilabel cell

每次用户双击我的手机时,我都会尝试展示标签。我可以检测到水龙头,我可以从它们执行代码,但我遇到标签问题。出于某种原因,标签被添加两个,有时三个单元格应该添加到标签之下。我需要在被敲击的单元格上添加标签,不应该很难做到。

这是我的代码,提前谢谢。

[
{
    "name": "1st Online Soultions"
    "label": "01-02",
    "count": "577",
    "customerid": "129"
},
{
    "name": "Bookngo"
    "label": "01-020",
    "count": "2",
    "customerid": "129"
},
{
    "name": "Boutixury"
    "label": "07",
    "count": "1",
    "customerid": "14"
},
{
    "name": "Cruise Village"
    "label": "07",
    "count": "16",
    "customerid": "25"
},
 .................
]

1 个答案:

答案 0 :(得分:2)

您不应该使用didSelectRowAtIndexPath方法对单元格进行双击。

Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (nil == cell)
{
    cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

而是使用-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath检索选定索引路径的单元格,如下所示。

Cell *cell = [tableView cellForRowAtIndexPath:indexPath];

如果需要,您可以在didSelectRowAtIndexPath方法的末尾调用以下方法。

[tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: indexPath]
     withRowAnimation: UITableViewRowAnimationNone];