当用户在tableview中向上滑动时,如何保持UI-Searchbar可见

问题描述 投票:0回答:1

在我的应用程序中,当用户向下滑动时,UI-searchbar变得消失,这是我想要的,但当用户向上滑动时,我希望UI-Search栏立刻变得可见。 enter image description here enter image description here

我想让代码告诉我用户在tableview单元格中向上滑动并启用uisearch-bar。

ios uisearchbar uislider
1个回答
0
投票

您可以使用tableHeaderView进行此类工作。

在你的viewDidLoad写下面的代码。

- (void)viewDidLoad
{

**// Take one view and subview that view in the tableview.**

    UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)];
    [self.Yourtablename addSubview:viewsearch];


**//Now take any controls which you want to show in your header. e.x label,button,searchbar**

UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;    
[viewsearch addSubview:lbl1];
lbl1.text= @"BUY THE NEW APPLE TV FROM THE APPSTORE";

**//Here is the code.With the help of this code  when you scroll UP the headerview hide.**


 self.Yourtablename.tableHeaderView = viewsearch;
 self.Yourtablename.contentOffset = CGPointMake(0, CGRectGetHeight(viewsearch.frame));

}

可能它会帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.