隐藏UITableView的滚动条以及修改滚动条的颜色,UITableView 滚动到指定行 section

   
//隐藏

self.tableView.showsVerticalScrollIndicator = NO;

//修改颜色
self.tableView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
 
 
 

UITableView 滚动到指定行 section

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];

    CGRect frame = [tableview rectForSection:indexPath.section];

    [tableview setContentOffset:CGPointMake(0, frame.origin.y) animated:YES];

 
 
 
 

 

 选中某一行后想要tableView自动滚动使得选中行始终处于table的top、middle或者bottom,使用以下方法中的一个就可以实现:

[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

//    [tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionBottom animated:YES];

h文件:
Java代码  收藏代码
  1. @interface GKViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>{  
  2.     BOOL bCheck[50];  
  3. }  
m文件:
Java代码  收藏代码
  1. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
  2. {  
  3.     return 50;  
  4. }  
  5.   
  6. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
  7. {  
  8.     if (bCheck[indexPath.row]) {  
  9.           
  10.         return 100;  
  11.     }else{  
  12.           
  13.         return 50;  
  14.     }  
  15.       
  16. //    return 50;  
  17. }  
  18.   
  19. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  20. {  
  21.     static NSString *CellIdentifier = @"Cell";  
  22.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  23.     if(cell == nil)  
  24.     {  
  25.         cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault  
  26.                                     reuseIdentifier:CellIdentifier];  
  27.         cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;  
  28.     }  
  29.       
  30.     cell.textLabel.text=[NSString stringWithFormat:@"%@%i",@"话题",indexPath.row];  
  31.       
  32.     return cell;  
  33. }  
  34.   
  35. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  36. {  
  37.     [self initCheck];  
  38.       
  39.       
  40.     bCheck[indexPath.row] = YES;  
  41.       
  42.     [tableView reloadData];  
  43.     bCheck[indexPath.row] = NO;  
  44.       
  45. [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];  
  46. //    [tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionBottom animated:YES];  
原文地址:https://www.cnblogs.com/allanliu/p/4215624.html