jeudi 4 décembre 2014

Programiticaly Multiple Columns in Tableview ios

I am trying to create a table with multiple columns, i am using array of cells. Following is my code, I get single columns every time.



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"Cell";


TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];


cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] ;


CGFloat x = 0.0f; UIView *lastCol = [[cell columnCells] lastObject]; if (lastCol) x = lastCol.frame.origin.x + lastCol.frame.size.width;


for (int i = 0; i < 2; i++) {



UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, i, 40.0f)] ;
UIView *gridCell = l;

CGRect f = gridCell.frame;
f.origin.x += x;
gridCell.frame = f;

[cell.contentView addSubview:gridCell];

CGFloat colWidth = [self widthForColumn:i];

x += colWidth + 1.0f;
[[cell columnCells] addObject:gridCell];


} for (int i = 0; i < 2; i++) {

UILabel l = (UILabel)[cell columnCells][i]; l.text =self.department[indexPath.row];

}


return cell; }





Aucun commentaire:

Enregistrer un commentaire