我正在使用自定义类来制作tableview单元格。当滚动tableview值时,什么消失了?

时间:2013-11-27 11:25:10

标签: ios

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {



static NSString *leftTableIdentifier = @"Cell";

customTableCell *cell = (customTableCell *)[tableView dequeueReusableCellWithIdentifier:leftTableIdentifier];

if (!cell)
{
    //cell = [[customTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:leftTableIdentifier];
    NSArray *ar = [[NSBundle mainBundle]loadNibNamed:@"customTable" owner:nil options:nil];
                    cell= [ar objectAtIndex:0];
}

BOOL isSelected = [selectedArray containsObject:indexPath];
cell.lblInfo.numberOfLines = isSelected?0:2;

NSString *text = [items objectAtIndex:indexPath.row];
cell.lblInfo.text = text;


NSString *buttonTitle = isSelected?@"See Less":@"See More";
[cell.btnTitle setTitle:buttonTitle forState:UIControlStateNormal];
[cell.btnTitle setBackgroundColor:[UIColor redColor]];
[cell.btnTitle addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
[cell.btnTitle setTag:indexPath.row];

cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;

}

1 个答案:

答案 0 :(得分:0)

尝试

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *leftTableIdentifier = @"Cell";

    customTableCell *cell = (customTableCell *)[tableView dequeueReusableCellWithIdentifier:leftTableIdentifier];

    if (!cell)
    {
        //cell = [[customTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:leftTableIdentifier];
        NSArray *ar = [[NSBundle mainBundle]loadNibNamed:@"customTable" owner:nil options:nil];
        cell= [ar objectAtIndex:0];

        BOOL isSelected = [selectedArray containsObject:indexPath];
        cell.lblInfo.numberOfLines = isSelected?0:2;

        NSString *text = [items objectAtIndex:indexPath.row];
        cell.lblInfo.text = text;


        NSString *buttonTitle = isSelected?@"See Less":@"See More";
        [cell.btnTitle setTitle:buttonTitle forState:UIControlStateNormal];
        [cell.btnTitle setBackgroundColor:[UIColor redColor]];
        [cell.btnTitle addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
        [cell.btnTitle setTag:indexPath.row];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}