Multi Row-Column tableView in iOS SDK [closed]

﹥>﹥吖頭↗ 提交于 2020-01-07 04:49:08

问题


In my app, How can I show the data in tableView as per following image.

Help me to solve this problem?

Thank You.


回答1:


You can use collectionView for this purpose.As it is looking like a grid View , so UICollectionView will be perfect choice to be used as grid sheet.

You can use the RFQuiltLayout library, which is a subclass of UICollectionView. Here is the code you can use to create your layout:

- (void)viewDidLoad {

    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];

    RFQuiltLayout* layout = (id)[self.collectionView collectionViewLayout];
    layout.direction = UICollectionViewScrollDirectionVertical;
    layout.blockPixels = CGSizeMake(100, 40);
    [self.collectionView reloadData];
    [super viewDidLoad];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 21;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier=@"cellIdentifier";

    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];


    UILabel* label = (id)[cell viewWithTag:21];
    if(!label) label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];

    label.backgroundColor=[UIColor blueColor];
    label.tag=21;
    label.textColor=[UIColor whiteColor];
    label.textAlignment=NSTextAlignmentCenter;
    [label setAutoresizingMask:(UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth)];
    [cell.contentView addSubview:label];

    label.text=[NSString stringWithFormat:@"Task%i",indexPath.row];
    if (indexPath.row==0) {
        label.text=@"Category";
    }

    if (indexPath.row==3) {
        label.text=@"Communication";
    }

    if (indexPath.row==8) {
        label.text=@"Meeting";
    }

    if (indexPath.row==13) {
        label.text=@"Others";
    }

    [cell setAutoresizesSubviews:YES];
    cell.backgroundColor=[UIColor greenColor];
    return cell;
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UIEdgeInsets insets=UIEdgeInsetsMake(10, 10, 10, 10);
    return insets;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 2;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 2;
}

#pragma mark – RFQuiltLayoutDelegate

- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.row==0)return CGSizeMake(2, 1);
    if (indexPath.row==3) return CGSizeMake(2, 2);
    if (indexPath.row==8) return CGSizeMake(2, 2);
    if (indexPath.row==13) return CGSizeMake(2, 2);

    return CGSizeMake(1, 1);
}

- (UIEdgeInsets)insetsForItemAtIndexPath:(NSIndexPath *)indexPath {
    return UIEdgeInsetsMake(2, 2, 2, 2);
}




回答2:


If you want to display exactly as shown in the figure, ignore my answer. You can display it using two uitableviews. First you need to create a tableview with header name category There must be two rows.ie, communication and meeting. if user selects the communication, then navigates to the second table view in second table view, header names are Mon,tue,Wed,Thur for each section. then displays the tasks in each rows.



来源:https://stackoverflow.com/questions/16910832/multi-row-column-tableview-in-ios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!