Tableview Checkmark不会使用带有目标C的iOS故事板显示

时间:2015-12-09 09:33:48

标签: objective-c uitableview storyboard

我正在尝试使用tableview创建tableviewcell,并且每当用户选择tableviewcell它应该应用checkmark。我的tableview和tableview单元格由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;
}

2 个答案:

答案 0 :(得分:1)

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

- (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;
}

答案 1 :(得分:0)

在tableview委托函数

中写下这个
- (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;
}