在预先填充的tableview上勾选标记

时间:2014-04-28 07:31:12

标签: ios objective-c uitableview

我有一个在XCODE中创建的tableview(没有代码)。

enter image description here

当我按下其中一行时,我正试图在右侧打勾,我正在使用IOS7。

这引起了一些噩梦。这是我正在实施的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [UITableViewCell new];


    cell.tintColor = [UIColor blackColor];

    if(cell.selected){
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else{
        [cell setAccessoryType:UITableViewCellAccessoryNone];

    }


}

1 个答案:

答案 0 :(得分:0)

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

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];


    cell.tintColor = [UIColor blackColor];

    if(cell.selected){
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else{
        [cell setAccessoryType:UITableViewCellAccessoryNone];

    }


}