在UITableView上面添加UIView

时间:2015-11-04 01:25:30

标签: ios objective-c iphone uitableview uiview

我目前在UITableView上面添加了UIView。它可以工作,但看起来像空的UITableViewCell'它出现在下面这样:

enter image description here

我的第二个视图的代码(.m文件):

-(id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    NSLog(@"Calld");
    self.backgroundColor = [UIColor whiteColor];
    [self addLabel];
    return self;
}

-(void)addLabel{

    UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(8, 220, 304, 128)];
    fromLabel.text = @"( Щелкните на экран, чтобы добавить задачи )";

    fromLabel.numberOfLines = 3;
    fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
    fromLabel.adjustsFontSizeToFitWidth = YES;
    fromLabel.adjustsLetterSpacingToFitWidth = YES;
    fromLabel.minimumScaleFactor = 10.0f/12.0f;
    fromLabel.clipsToBounds = YES;
    fromLabel.backgroundColor = [UIColor clearColor];
    fromLabel.textColor = [UIColor blackColor];
    fromLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:fromLabel];
}

主要观点:

 InitialView *initView = [[InitialView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];

    [self.view addSubview:initView];

如何删除那些空行,然后再次删除视图和显示表?

2 个答案:

答案 0 :(得分:1)

在您的情况下,您可以从标签高度增加或设置InitialView背景颜色以隐藏这些空行。 如果你想删除那些把这个代码放在你有桌面视图的控制器中。

yourTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

并删除您的视图,以便再次显示您的tableview使用。

[initView removeFromSuperview];

答案 1 :(得分:1)

您不需要删除空行或视图。 只需将 tableview隐藏直到数据未加载 - 在viewWillLoad中

在填写了tableview并且重新加载tableview后使 tableview.hidden = NO;

默认情况下,除非您已将tableview的分隔线颜色设为clearcolor,否则将显示空行。