UITableview title not showing again if scrolling

I have a UITableview Controller that has a search bar in the title. When I scroll through the table view, and it bounced. But the search bar is hiding. when I scroll down, a search bar is displayed. can someone tell me how can i show the search bar again?

I tried the following code, but it does not work smoothly:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        //scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        CGPoint newOffset = CGPointMake(0, -[self.tableView  contentInset].top);
        [self.tableView setContentOffset:newOffset animated:YES];
    }
}

Here is a screenshot to view before scrolling: enter image description here

And this is the wrong look after scrolling:

enter image description here

+4
source share
2 answers

How to disable the animation and put the custom animation as follows:

, MAcro. , 35 25.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
            CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
            if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {

    [UIView animateWithDuration: 1.0
                      animations: ^{
                          scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
                      }completion: ^(BOOL finished){
                      }
        ];
            } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
                CGPoint newOffset = CGPointMake(0, -[self.tableView  contentInset].top);


[UIView animateWithDuration: 1.0
                  animations: ^{
                      [self.tableView setContentOffset:newOffset animated:NO];
                  }completion: ^(BOOL finished){
                  }
    ];
            }
}
+1

- (void)scrollViewDidScroll:(UIScrollView *)scrollView  
{  
    CGFloat sectionHeaderHeight = 40;  
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {  
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);  
    }  
    else if (scrollView.contentOffset.y>=sectionHeaderHeight) {  
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);  
    }  
} 

, 40, 35 25, , tableview , 40 .

0

All Articles