iOS UITableView内容偏移在iOS7中不起作用

时间:2015-05-14 08:40:53

标签: ios objective-c uitableview ios7 contentoffset

在我的应用中,我的UITableView标题中有一个搜索栏。我试图将内容偏移设置为UITableView以隐藏搜索栏,但它给了我一些问题。

最后我这样解决了:

- (void)viewWillAppear:(BOOL)animated
{
    [self performSelector:@selector(hideSearchBar) withObject:nil afterDelay:0.0f];
}

- (void)hideSearchBar 
{
    self.tblView.contentOffset = CGPointMake(0, 40);
}

问题是它只适用于iOS 8.

如何才能正确实现这一功能,适用于iOS 7和iOS 7 8 ????

抱歉我的英语不好。提前谢谢。

2 个答案:

答案 0 :(得分:1)

如果按function clever_foo(n::Int) eval(quote function clever_foo_impl() s::Int = 0 for i in 1:1000000000 s += $(Expr(:call,:+,[1 for j in 1:n]...)) end return s end end) return clever_foo_impl() end (推荐方式)设置标题,请尝试

self.tblView.tableHeaderView = yourSearchBar

self.tblView.tableHeaderView = nil;

隐藏它。

PS。 self.tblView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero]; 应该是一个实例变量或将来可以方便地显示的属性。

答案 1 :(得分:1)

- (void)viewDidLoad
{
    [super viewDidLoad];

    UISearchBar *bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];

    self.tableView.tableHeaderView = bar;

}

- (void)viewWillAppear:(BOOL)animated
{
    [self performSelector:@selector(hideSearchBar) withObject:nil afterDelay:0.0f];
}

- (void)hideSearchBar
{
    self.tableView.contentOffset = CGPointMake(0, -24);
}
相关问题