2017-10-06 15 views
0

テーブルのスクロールに問題があります。テーブルを下にスクロールすると、テーブルの上にあるボタンが同じ位置に維持され、テーブルが下にスクロールしている間にボタンが消えることが必要です。テーブルビューのスクロールビューのカスタマイズ

これは私のコードです:

@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:@ "アルタ・デ・SERVICIOS" forState:UIControlStateNormal];

これはこの画面の様子をイメージしたもので、StoryboardとXibをテーブルに使用しています。

enter image description here

答えて

1

これは、セクションヘッダは、プレーンスタイルテーブルビューでどのように働くかです。適切な例については、電話アプリの連絡先タブを参照してください。

ボタンが1つしかなく、テーブルビューの最上部に表示したい場合は、テーブルビューをスクロールしてスクロールする場合は、viewForHeaderInSectionを実装する代わりに、ボタンビューをテーブルとして設定する必要がありますビューのtableHeaderView

は、あなたの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方法を削除します。

+0

私に例を教えてもらえますか?申し訳ありませんが、私は客観的なCの初心者です。 –

+1

私の更新答えを見てください。 – rmaddy

+0

ありがとう、これは私の問題を解決! –

関連する問題