粘性UITableView标题如iOS中的App Store精选页面?

时间:2015-11-16 04:11:57

标签: ios uitableview

如何在UITableView中模仿此行为。其中,如果我把桌子拉到DOWN,那么标题会在停止处停留,但是如果我向上滚动表格,标题就会随之而来。

就像应用程序商店一样。 (向上滚动) enter image description here

(向下滚动) enter image description here

1 个答案:

答案 0 :(得分: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.tbluser.tableHeaderView = viewsearch;
        self.tbluser.contentOffset = CGPointMake(0, CGRectGetHeight(viewsearch.frame));
        }

可能会帮助你。