2016-06-24 7 views
0

私は(0,0,0,0)に設定された自動レイアウトのコーナーでテーブルビューを使用しています。テーブルビューにカスタムセルが設定されていました。scrollToRowAtIndexPathは正しく動作しません。cellForRowAtIndexPathメソッドはこのようになりますscrollToRowAtIndexPathは正常に動作していませんか?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    RTableViewCell *cell = (RTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell==nil) 
    { 
     for (UIView *currentView in tableView.subviews) { 
      if ([currentView isKindOfClass:[UIScrollView class]]) { 
       ((UIScrollView *)currentView).delaysContentTouches = NO; 
       break; 
      } 
     } 
     UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 
     myBackView.backgroundColor =[UIColor colorWithRed:216/255.0 green:231/255.0 blue:244/255.0 alpha:1.0]; 
     cell.selectedBackgroundView = myBackView; 

    return cell;  
} 

私は、動的なセクション数とその内部の動的な行数を持っていました。 この

dispatch_async(dispatch_get_main_queue(), ^{ 
    //int indexValue = (int)[sections indexOfObject:string]; 
    [rtable reloaddata]; 
     NSIndexPath *rowIndexPath = [NSIndexPath indexPathForRow:0 inSection:6]; 
    [self.rtable scrollToRowAtIndexPath:rowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; 
}); 

誰もが私が間違っているつもり場所を知っているように私のviewDidAppearに私が呼び出すのですか?

+0

期待される成果と何が起こるの代わりは何ですか? – Code

+0

テーブルビューを0行目の6番目のセクションにしたいのですが、3番目のセクションまでしかスクロールしていません。 – hacker

+0

セクション6のpositionTopにスクロールするのに十分な行がありますか? contentInsetを使用してボトムスペースを追加する必要がある場合があります – danh

答えて

0

viewWillAppearまたはviewDidLayoutSubviewsにコードの下に試してみてください。

[rtable reloaddata]; 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 

     NSIndexPath *rowIndexPath = [NSIndexPath indexPathForRow:0 inSection:6]; 
     [self.rtable scrollToRowAtIndexPath:rowIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 

    }); 
関連する問題