Ios 自定义表节页脚视图-标签不可见

Ios 自定义表节页脚视图-标签不可见,ios,uitableview,Ios,Uitableview,我用一个UITableViewController在Xcode中创建了一个新的单视图项目(使用故事板)。以下是设置代码: - (void)viewDidLoad { [super viewDidLoad]; _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; _footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth

我用一个UITableViewController在Xcode中创建了一个新的单视图项目(使用故事板)。以下是设置代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    _footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 44, 44)];
    l.text = @"Label Label Label Label Label Label Label Label Label";
    l.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    l.backgroundColor = [UIColor clearColor];

    [_footerView addSubview:l];

    _footerView.backgroundColor = [UIColor lightGrayColor];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return _footerView.frame.size.height;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return _footerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [tableView dequeueReusableCellWithIdentifier:@"Cell"];
}
我希望自定义表页脚视图中的标签以x=60绘制,但当我运行项目时,首先标签是不可见的(在纵向视图中,屏幕附着)。然后,如果我旋转一次,它就会变得可见,如果我旋转回到纵向,它就会可见

我错过了什么


您似乎正在初始化宽度和高度为44px的页脚视图,但添加了超出其边界的标签

请尝试以下操作:

_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 44)];

_footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

UILabel *l = [[UILabel alloc] initWithFrame:CGRectInset(_footerView.bounds, 60.0f, 0.0f)];
l.text = @"Label Label Label Label Label Label Label Label Label";
l.autoresizingMask = UIViewAutoresizingFlexibleWidth;
l.backgroundColor = [UIColor clearColor];

[_footerView addSubview:l];

_footerView.backgroundColor = [UIColor lightGrayColor];
还有一点,如果可以的话,尽量不要使用
[UIColor clearColor]
作为标签背景色,因为这会显著降低滚动性能。在这种情况下,您应该使用
[UIColor lightGrayColor]
,使其与superview匹配