How to display multiple columns in a UITableView?

Solution 1:

I think the correct way of doing this is UICollectionView. Started with UITableView and finally failed at some point due to unexpected behavior while trying to implement scrolling both left-right and up-down.

Please check this awesome post for a complete and up-to-date solution: http://www.brightec.co.uk/blog/uicollectionview-using-horizontal-and-vertical-scrolling-sticky-rows-and-columns

Result will be like this:

enter image description here

Solution 2:

You can define a custom cell in IB, which will contain 3 labels and in function:

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

         static NSString *DetailCellIdentifier = @"DetailCell";

         UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:DetailCellIdentifier];

         if (cell == nil) {
            NSArray *cellObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCell" owner:self options:nil];
            cell = (UITableViewCell*) [cellObjects objectAtIndex:0];
        }

        // setup your cell
     }

when you define the cell in IB give each label a tag, so when you need to put a text there you can retrieve it by tag like this:

        label = (UILabel *)[cell viewWithTag:NAME_TAG];
        label.text = myObject.name; 

and repeat this with other 2 labels. The tag is a unique number.

Put this code instead //setup your cell comment

Solution 3:

I have created UIGridView. I believe your problem can be solved using the same technique.

You can learn the source code of UIGridView. The code is really short.

Solution 4:

Bit late to the party, but we've open sourced our fully featured table component:

https://github.com/flexicious/iOSDataGrid

Some screenshots:

http://www.ioscomponents.com/Home/IOSDataGrid

Feel free to use!