UITableView部分标题消失

时间:2015-01-30 07:51:03

标签: ios objective-c uitableview

我遇到了节标题视图的问题。当我通过滑动删除我的单元格时,节标题视图就会消失......

@property(强大,非原子)UILabel * myView;

- (UILabel *)myView {
    if (!_myView) {
        _myView = [[UILabel alloc] init];
        _myView.textAlignment = NSTextAlignmentCenter;
        _myView.textColor = [Utils grayTextColor];
        _myView.font = [UIFont systemFontOfSize:13];
        _myView.numberOfLines = 0;
    }

    if (self.data.count > 0) {
        _myView.text = @"HAS DATA TEXT";
    }
    else {
        _myView.text = @"HAS NO DATA TEXT";
    }

    [_myView sizeToFit];

    CGRect frame = _myView.frame;
    frame.size.width = self.tableView.frame.size.width;
    frame.size.height = 30;
    _myView.frame = frame;

    return _myView;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return self.myView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.data removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

1 个答案:

答案 0 :(得分:0)

我在iOS 7和8下尝试你的代码。

部分标题仍在此处。