UITableView页脚没有出现

时间:2016-06-30 19:25:29

标签: ios uitableview

我有一个包含多个部分的uitableview。我试图在tableview的页脚中添加一个笔尖。如果我以编程方式创建一个视图,它会出现,但我无法将笔尖放在页脚中。当NSBundle线被注释掉时,电视看起来非常好,但如果我取消注释,我只会在模拟器中看到黑屏。

- (void)viewDidLoad {
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.tableView.tableFooterView = [[[NSBundle mainBundle] loadNibNamed:@"footerView" owner:self options:nil] lastObject];

//    CGRect footerRect = CGRectMake(0, 0, 375, 100);    
//    UIView *wrapperView = [[UIView alloc] initWithFrame:footerRect];
//
//    UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
//    tableFooter.textColor = [UIColor blueColor];
//    tableFooter.backgroundColor = [UIColor purpleColor];
//    tableFooter.font = [UIFont boldSystemFontOfSize:15];
//    tableFooter.text = @"test";
//
//    [wrapperView addSubview:tableFooter];
//
//    self.tableView.tableFooterView = wrapperView;
}

nib screenshot

我是否错误地实例化了笔尖?

1 个答案:

答案 0 :(得分:0)

作为一个实际的答案,因为它允许我发布代码。我设置了自己的小型演示项目,其中包含一个非常简单的“FooterView.xib”文件(从XCode的视图资源模板创建)。我将其中的视图设置为自由形式,并给它一个足够小的框架,因此它不会在视觉上杀死表格。然后在我的表的ViewController中我做了:

UIView *test;
NSArray *results = [[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:self options:nil];
test = [results lastObject];
self.tableView.tableFooterView = test;

将线分开一点允许我调试(我在self.tableView.tableFooterView = test之前设置断点并确保测试是一个视图(我在xib中定义了帧,所以我可以识别它)。

编辑:这是我的测试应用repo

相关问题