【发布时间】:2016-05-19 06:50:09
【问题描述】:
我的 tableview 控制器中有一个自定义分段控件,tableview 的标题中有一个搜索栏。当我向上滚动到最后一个单元格时,tableview 会弹回来。但问题是:我的搜索栏隐藏在分段控件后面,视图底部出现一个空白。我希望如果用户向上滚动表格视图,它会反弹并返回到之前的位置,如第一个屏幕截图所示。
这是我的分段控制代码:
self.projectSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Active Projects", @"All Projects", nil]];
[self.projectSegmentControl addTarget:self action:@selector(actionSelectProject) forControlEvents:UIControlEventValueChanged];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width -20;
self.projectSegmentControl.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-screenWidth-5,10, screenWidth, 30.0);
_segmentControlView = [[UIView alloc] initWithFrame: CGRectMake(0,60, screenRect.size.width,47.0)];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_segmentControlView.backgroundColor = [UIColor whiteColor];
self.projectSegmentControl.backgroundColor = [UIColor whiteColor];
[_segmentControlView addSubview:self.projectSegmentControl];
[appDelegate.window addSubview:_segmentControlView];
self.projectSegmentControl.selectedSegmentIndex = 0;
CGFloat screenHeight = screenRect.size.height;
if(screenHeight==480 || screenHeight==568)
{
CGPoint newOffset = CGPointMake(0, -[self.tableView contentInset].top);
[self.tableView setContentOffset:newOffset animated:YES];
}
UIFont *font = [UIFont fontWithName:@"Avenir" size:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
[_projectSegmentControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
当我向上滚动 tableview 反弹但搜索栏隐藏在分段控件后面时。
PS:如果需要,我会添加代码。提前致谢
【问题讨论】:
-
请发布您的代码
-
我已经添加了我的分段控件的代码。如果你想要更多的代码,我会添加。
标签: ios objective-c iphone uitableview uisearchbardisplaycontrol