1、选择tableview中有多少个分区;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [titleArray count];//返回标题数组中元素的个数来确定分区的个数
}
2、指定分区中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;//默认返回1
}
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
3、比较重要的一点
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCellalloc]
initWithFrame:CGRectZero
reuseIdentifier:CellIdentifier] autorelease];
//往cell里面添加内容
if(indexPath.section == 0 && indexPath.row == 0)
{
//第一区,第一行
//添加ui到cell
}
}
4、如果处理tableview中上面的header
方法一,去除:_mainTable.contentInset = UIEdgeInsetsMake(<span style="font-family:Microsoft YaHei;">sectionHeight</span>, 0, 0, 0);
方法二,隐藏: ontentTableView.tableHeaderView = nil;