在我的应用中,我的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 ????
抱歉我的英语不好。提前谢谢。
答案 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);
}