1.如何设置tableview  每行之间的分割线

self.table.separatorStyle=UITableViewCellSeparatorStyleSingleLine;


2.如何让cell 能够响应 select,但是选中后的颜色又不发生改变呢,那么就设置

法一:完全不变色

cell.selectionStyle  =  UITableViewCellSelectionStyleNone;

法二:变下色马上恢复

[tableView deselectRowAtIndexPath:indexPath animated:NO];


3.如何获得 某一行的CELL对象

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;


4.如何获得 某一行的CELL对象

UITableViewCell *ta = [self.table cellForRowAtIndexPath:indexPath];


5.行缩进

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSUInteger row = [indexPath row];

    return row;

}


6.TableView添加时最顶端有段空白,如何去掉最上面的那一段空白

法一:在.pch文件中写一段宏

#define kNavigationBarFit(obj) [objsetEdgesForExtendedLayout:UIRectEdgeNone];\

[obj setExtendedLayoutIncludesOpaqueBars:NO];\

[obj       setModalPresentationCapturesStatusBarAppearance:NO];\

self.navigationController.navigationBar.translucent= NO;



法二:在定义tableView时写上

[self  setEdgesForExtendedLayout:UIRectEdgeNone];


7.怎么解决Cell重用问题

在重用前把cell里的子视图删了

    for (UIView *v in cell.contentView.subviews) {

        [v removeFromSuperview];

    }


8.设置索引,返回的是一个数组,如例子,返回0代表第一组的索引,1代表第二组索引,2待变第三组索引

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

    return @[@"0",@"1",@"2"];

}


9.

    self.table deleteRowsAtIndexPaths: withRowAnimation:

    self.table insertRowsAtIndexPaths: withRowAnimation:

    self.table insertSubview: aboveSubview:

    self.table insertSubview: atIndex:

    self.table insertSubview: belowSubview:


10.设置tableView的背景为透明

[self.table setBackgroundColor:[UIColor colorWithWhite:0.8 alpha:0.5]];

11.设置tableViewCell的背景为透明

cell.backgroundColor = [UIColor clearColor];

12.设置tableView分割线类型

[self.table setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];


13.cell.accessoryType = UITableViewCellAccessoryDetailButton;

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath


   //自定义cell右边箭头图标

    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"icon_detail.png" ]];




14.选中行时跳到顶端,UITableViewScrollPositionTop后面的top可改变,换成UITableViewScrollPositionMiddle

[self.table selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];


15.获取显示在屏幕上的cell,返回的是一个存放indexPath的数组

 [self.tableView indexPathsForVisibleRows];


16.视图显示时让tableview滚动到哪行

用tableView调用   - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated];