How to display multiple columns in a UITableView?

2019-01-04 02:51发布

I want to display multiple columns in a UITableView.

For Example:

TableView

   FName        LName    Age

   -----        -----    ---

   Abby         Michale   34   

6条回答
Rolldiameter
2楼-- · 2019-01-04 03:11

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

查看更多
聊天终结者
3楼-- · 2019-01-04 03:12

Create a custom UIView subclass containing, say, three UILabel elements as subviews. Then set the cell's contentView property to this custom view.

查看更多
何必那么认真
4楼-- · 2019-01-04 03:13

add three labels as sub viewsinto uitableview cell's content.then assign apprrpriate values to it eg:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];


}

//frame should be set accordingly(means should be framed accordingly).

UILabel *l1=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100,100)];

UILabel *l2=[[UILabel alloc]initWithFrame:CGRectMake(110,10,100,80)];
UILabel *l3=[[UILabel alloc]initWithFrame:CGRectMake(115,60,100,50)];

[cell.contentView addSubview:l1];
[cell.contentView addSubview:l2];
[cell.contentView addSubview:l3];
 return cell;
 }
查看更多
叛逆
5楼-- · 2019-01-04 03:15

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

查看更多
\"骚年 ilove
6楼-- · 2019-01-04 03:33

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!

查看更多
神经病院院长
7楼-- · 2019-01-04 03:37

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.

查看更多
登录 后发表回答