iOS中UITableView单选标记的实现

来源:互联网 发布:模拟炒股软件 推荐 编辑:程序博客网 时间:2024/04/29 04:37

摘录自《iPhone3开发基础教程》第202页:

#pragma mark -

#pragma mark Table Delegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    int newRow = [indexPath row];

    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

    if(newRow != oldRow)

    {

        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

        newCell.accessoryType = UITableViewCellAccessoryCheckmark;

        

        UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];

        oldCell.accessoryType = UITableViewCellAccessoryNone;

        lastIndexPath = indexPath;

    }

    

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

 

运行结果:要是点的是同一行,选中标记就不变。要是另外选择了一行,该行就设上“对钩”,原来那一行就没有标记了。


转自: http://hi.baidu.com/jt_one/item/bc915f31e6e12e21b2c0c5eb

0 0
原创粉丝点击