[英]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.