OC中UITableView的属性用法


    //删除第一个元素

    [self.data removeObjectAtIndex:0];

    

    //刷新表视图---重新执行数据源方法和代理方法

    [self.tableView reloadData];

    

    

    //把第2个单元格的内容改为呵呵

    //构建IndexPath

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

    //取到单元格

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    cell.textLabel.text = @"呵呵";

    

    //输出在屏幕上显示的单元格的内容

    NSArray *cells = [self.tableView visibleCells];

    for (UITableViewCell *cell in cells) {

        NSLog(@"%@", cell.textLabel.text);

    }

    

    //输出在屏幕上显示的单元格的下标

    NSArray *indexPaths = [self.tableView indexPathsForVisibleRows];

    for (NSIndexPath *indexPath in indexPaths) {

        NSLog(@"%ld", indexPath.row);

    }

    

    

    // 滑动到指定的位置,可以配置动画

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

    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:true];


}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark -UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return self.data.count;

}




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

{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    NSString *fontName = self.data[indexPath.row];

    cell.textLabel.text = fontName;

//    cell.textLabel.font = [UIFont fontWithName:fontName size:20];

    

    return cell;

}


//设置section头部、尾部视图的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 80;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 80;

}

//自定义头标题

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];

    label.text = @"123213";

    label.backgroundColor = [UIColor whiteColor];

    [view addSubview:label];

    NSLog(@"%@:",view);

    view.backgroundColor = [UIColor blueColor];

    return view;

}

//设置单元格的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.row == 0) {

        return 100;

    }else if (indexPath.row == 1) {

        return 200;

    }

    return 44;

}