如何使用故事板时,将UITable标题粘到屏幕的顶部?

我已经使用这个post标题 : StoryBoards中的表头视图

但是我无法在滚动的时候将标题粘贴(修复)到屏幕的顶部。

这怎么能实现?

PS表风格很简单,当我厌倦了重载viewForHeaderInSection和返回出口的标题视图,它只是变得更糟。

提前致谢!

这是我相信使标题视图坚持到桌面的代码(这不是它的默认行为):

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { CGRect rect = self.tableHeaderView.frame; rect.origin.y = MIN(0, self.tableView.contentOffset.y); self.tableHeaderView.frame = rect; } 

另一种方法是对第一部分使用标题视图。 您不能在viewForHeaderInSection使用任何子视图 ,您必须返回尚未处于视图层次结构的视图。 该方法的优点是,节标题视图被devise为在桌面上,缺点是你可能想要在该function部分的标题,这将打破解决scheme。

我能够做到这一点(至less在iOS 6)这样做,不知道为什么这个事情:)

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(self.headerManualView == nil) { //allocate the view if it doesn't exist yet headerManualView = [[UIView alloc] init]; //create the button UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(10, 3, 250, 44)]; //the button should be as big as a table view cell txtField.borderStyle = UITextBorderStyleRoundedRect; //set action of the button //[txtField addTarget:self action:@selector(removeAction:) forControlEvents:UIControlEventTouchUpInside]; //add the button to the view [headerManualView addSubview:txtField]; } //return the view for the footer return headerManualView; } 

我认为在故事板中使用UIViewController而不是UITableViewController来实现这一点更好。 只需在视图顶部放置一个标题,并在标题下放置一个UITableView。