How to make UITable header stick to the top of the screen when using Storyboards?

后端 未结 3 1552
感情败类
感情败类 2020-12-31 20:18

I\'ve made header using this post: Table Header Views in StoryBoards

But i am unable to make header stick (fix) to the top of the screen while scrolling.

How

3条回答
  •  难免孤独
    2020-12-31 21:18

    I was able to do it (at least in iOS 6) like this, don't know why this thing works:)

    - (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;
    }
    

提交回复
热议问题