使用 iOS 故事板和 objective C 不显示 Tableview 复选标记

Tableview Checkmark not display using iOS storyboard with objective C

我正在尝试用 tableviewcell 创建 tableview,每当用户 select 和 tableviewcell 时,它应该应用 checkmark。我的 tableview 和 tableview cell 由 iOS storyboard 创建的所有内容。请逐步帮助解决我的问题。

我的来源:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cellID";

    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[myTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    NSString *stringForCell;
    if (indexPath.section == 0) {
        stringForCell= [myData objectAtIndex:indexPath.row];
    }
    else if (indexPath.section == 1){
        stringForCell= [myData objectAtIndex:indexPath.row+ [myData count]];
    }
    [cell.sec_Label setText:stringForCell];
    return cell;
}

在你的表视图委托函数中写下这个

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    UITableViewCell* cell ....//some creation

    cell.accessoryType=UITableViewCellAccessoryCheckmark;
    //cell.accessView  don't set this, if set, use custom view. ignore accessoryType 


    return cell;
}

你可以这样做,首先在头文件中声明变量

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     static NSString *cellIdentifier = @"cellID";

     myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

     if (cell == nil) {
         cell = [[myTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
     }

     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     cell.accessoryType = UITableViewCellAccessoryCheckmark;
     cell.tintColor =  [UIColor blackColor];

     NSString *stringForCell; // Mention in header file

     if (indexPath.section == 0) {
          stringForCell= [myData objectAtIndex:indexPath.row];
     }
     else if (indexPath.section == 1){
          stringForCell= [myData objectAtIndex:indexPath.row+ [myData count]];
     }
     [cell.sec_Label setText:stringForCell];
     return cell;
}