[英]Customizing the Scroll View of a Table View
我的桌子滚动出现问题。 当我向下滚动桌子时,我在桌子上方的按钮保持在相同的位置并保持可见,我需要的是当我向下滚动桌子时该按钮将消失。
这是我的代码:
@implementation Mis_Servicios
- (void)viewDidLoad {
[super viewDidLoad];
[self SetTopBarStyle];
self.title = @"Mis servicios";
barButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"Editar"
style:UIBarButtonItemStylePlain
target:self
action:@selector(toggleEdit)];
self.navigationItem.rightBarButtonItem = barButtonItem;
#pragma mark - Table view data source
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
Cell_Detalles *cell = nil;
static NSString *CellIdentifier = @"Cell_registro";
cell =(Cell_Detalles *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"Cell_Detalles_7" owner:self options:nil];
cell = (Cell_Detalles *)[nib objectAtIndex:0];
cell.bt_preguntas.layer.cornerRadius = 20;
cell.bt_preguntas.backgroundColor = UIColorFromRGB(0x259026);
[cell.bt_preguntas setTitle:@"Alta de servicios" forState:UIControlStateNormal];
[cell.bt_preguntas setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cell.bt_preguntas addTarget:self action:@selector(goAltas) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"%f / %f",self.tableView.contentOffset.y, self.tableView.contentSize.height - self.tableView.frame.size.height);
if (self.tableView.contentOffset.y == self.tableView.contentSize.height - self.tableView.frame.size.height){
if (pagenumber < pages) {
++pagenumber;
[self ObtenerDatos];
}
}
}
这是表格上方的按钮:[cell.bt_preguntas setTitle:@“ Alta de servicios” forState:UIControlStateNormal];
这是该屏幕的图像,我正在为表使用Storyboard和Xib。
这是节标题在纯样式表视图上的工作方式。 请参阅“电话”应用程序的“联系人”选项卡以获取一个很好的示例。
如果只有一个按钮,并且希望它在表格视图的顶部,并且希望它随着表格视图的滚动而滚动,那么应该将按钮视图设置为表格视图的tableHeaderView
,而不是实现viewForHeaderInSection
。
将以下代码添加到您的viewDidLoad
方法中:
NSArray *nib= [[NSBundle mainBundle] loadNibNamed:@"Cell_Detalles_7" owner:self options:nil];
Cell_Detalles *cell = (Cell_Detalles *)[nib objectAtIndex:0];
cell.bt_preguntas.layer.cornerRadius = 20;
cell.bt_preguntas.backgroundColor = UIColorFromRGB(0x259026);
[cell.bt_preguntas setTitle:@"Alta de servicios" forState:UIControlStateNormal];
[cell.bt_preguntas setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cell.bt_preguntas addTarget:self action:@selector(goAltas) forControlEvents:UIControlEventTouchUpInside];
self.tableView.tableHeaderView = cell;
并删除整个viewForHeaderInSection
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.