/* * 假设数据都已放入self.dataArray */-(void)initTable{[self.tableViewregisterClass:[UserHeaderclass]forHeaderFooterViewReuseIdentifier:@"user"];[self.tableViewregisterClass:[PhotoCellclass]forCellReuseIdentifier:@"photo"];[self.tableViewregisterClass:[UITableViewCellclass]forCellReuseIdentifier:@"seperator"];}-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{returnself.dataArray.count;}-(NSInteger)tableView:(UITableView*)tableViewnumberOfRowsInSection:(NSInteger)section{return[(User*)self.dataArray[section]photos].count+1;//photos + seperator}-(UIView*)tableView:(UITableView*)tableViewviewForHeaderInSection:(NSInteger)section{UserHeader*header=(UserHeader*)[tableViewdequeueReusableHeaderFooterViewWithIdentifier:@"user"];header.user=self.data[section];returnheader;}-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{NSArray*photos=[(User*)self.dataArray[indexPath.section]photos];if(indexPath.row<photos.count){PhotoCell*cell=(PhotoCell*)[tableViewdequeueReusableCellWithIdentifier:@"photo"];cell.photo=photos[indexPath.row];returncell;}else{UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:@"seperator"];//configure for the first timereturncell;}}-(CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{NSArray*photos=[(User*)self.dataArray[indexPath.section]photos];if(indexPath.row<photos.count){//return photo cell height}else{return8.5;}}-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{NSArray*photos=[(User*)self.dataArray[indexPath.section]photos];if(indexPaht.row<photos.count){Photo*photo=photos[indexPath.row];//show large photo}}