在UITableView的顶部显示一条消息

问题描述:

我有一个UITableView,它支持NSFetchedResultsController。我想在列表顶部显示一条消息,例如“显示由XYZ过滤的项目”。我尝试在IB的屏幕顶部插入UIViewUILabel,但似乎不起作用。这甚至有可能做我想要的吗?在UITableView的顶部显示一条消息

如果你没有在表格视图上使用标题,你可以在你的UITableView的顶部添加一个自定义标题。

实现此方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

    UIView *myCustomView = [UIView alloc] init]; 
    //Add your label on myCustomView 

    return myCustomView; 

} 
+0

这样做,谢谢!我也必须在UITableViewDelegate中实现此方法来覆盖默认标题高度: - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; – Macondo2Seattle 2012-03-24 23:44:56

我的猜测是,你的.xib的主人是从一个UITableViewController子类,尝试将其更改为有一个UITableView和你的UILabel作为IB子视图一个UIViewController。