【问题标题】:Add UIView above UITableView在 UITableView 上方添加 UIView
【发布时间】:2016-02-04 09:00:54
【问题描述】:

我目前在 UITableView 上面添加 UIView。它可以工作,但看起来像空的 UITableViewCell 如下所示:

有我的第二个视图的代码(.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];

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

【问题讨论】:

    标签: ios objective-c iphone uitableview uiview


    【解决方案1】:

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

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

    并删除您的视图,以便您的 tableview 再次可见。

    [initView removeFromSuperview];
    

    【讨论】:

      【解决方案2】:

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

      在表格视图被填充并且您正在重新加载表格视图之后, 使 tableview.hidden = NO;

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

      【讨论】:

        猜你喜欢
        • 2017-01-16
        • 1970-01-01
        • 2016-10-29
        • 1970-01-01
        • 2018-11-06
        • 1970-01-01
        • 1970-01-01
        • 2013-05-09
        • 2019-07-25
        相关资源
        最近更新 更多