使用EWMultiColumnTableView第三库

本文介绍如何使用EWMultiColumnTableView实现多列表格视图,并提供了完整的代码示例及第三方库下载链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近项目需要需要使用类似EWMultiColumnTableView这样的表格。在网上搜到一个例子,我这里给这个例子加了注释以及之前的工程,可能因版本问题不能再Xcode5上运行,我这个重写写了一遍。

本文例子下载 : http://pan.baidu.com/s/1mgHO0tU

EWMultiColumnTableView第三库下载: http://pan.baidu.com/s/1hqkMBlE 

首先,将第三方库放入工程中

NSObject+NSObject_DelayedBlock.h

#import <Foundation/Foundation.h>

@interface NSObject (NSObject_DelayedBlock)
-(void)performBlock:(void (^) (void))block afterDelay:(NSTimeInterval)delay;

@end


NSObject+NSObject_DelayedBlock.m

-(void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay
{
    int64_t delta = (int64_t)(1.0e9 * delay);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block);
    
}

ViewController.h

#import <UIKit/UIKit.h>
#import "EWMultiColumnTableView.h"

@interface ViewController : UIViewController<EWMultiColumnTableViewDataSource>
{
    //内容的数组
    NSMutableArray* data;
    NSMutableArray* sectionHeaderData;
    
    CGFloat colWidth;        //数据区每列的宽度
    NSInteger numberOfSections; //数据有几个分区
    
    NSInteger numberOfColumns;  //数据的列数
    EWMultiColumnTableView* tbView;  //表格视图
    
}

@end

ViewController.m

//
//  ViewController.m
//  NewTableViewDemo
//
//  Created by 杜甲 on 14-1-11.
//  Copyright (c) 2014年 杜甲. All rights reserved.
//

#import "ViewController.h"
#import "NSObject+NSObject_DelayedBlock.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    numberOfColumns = 5;
    numberOfSections = 5;
    int sectionDistro[] = {5, 7, 4, 9, 2};
    colWidth = 240.0f;
    
    data = [[NSMutableArray alloc] init];
    sectionHeaderData = [[NSMutableArray alloc] init];
    
    for (int i = 0; i < numberOfSections; i++) {
        int rows = sectionDistro[i];
        NSMutableArray* a = [NSMutableArray array];
        for (int j = 0; j < numberOfColumns; j++) {
            int d = rand() % 100;
            NSMutableString* text = [NSMutableString stringWithFormat:@"S %d C %d",i,j];
            if (d < 66) {
                [text appendFormat:@"\nsecond line2222"];
            }
            
            if (d < 33) {
                [text appendFormat:@"\nthrid line88888"];
            }
            
            [a addObject:text];
            
            
        }
        [sectionHeaderData addObject:a];
        
        NSMutableArray* sectionArray = [NSMutableArray array];
        
        for (int k = 0; k < rows; k++) {
            NSMutableArray* rowArray = [NSMutableArray array];
            for (int j = 0; j < numberOfColumns; j++) {
                int d = rand() % 100;
                NSMutableString* text = [NSMutableString stringWithFormat:@"(%d , %d , %d)",i , k , j];
                if (d < 66) {
                    [text appendFormat:@"\nsecond line999"];
                }
                
                if (d < 33) {
                    [text appendFormat:@"\nthrid line888"];
                }
                [rowArray addObject:text];
            }
            [sectionArray addObject:rowArray];
        }
        [data addObject:sectionArray];
        
    }
    
    tbView = [[EWMultiColumnTableView alloc] initWithFrame:CGRectInset(self.view.bounds, 5.0f, 5.0f)];
    tbView.sectionHeaderEnabled = YES;
    tbView.dataSource = self;
    tbView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.view addSubview:tbView];

    [self performBlock:^{
        [tbView scrollToColumn:3 position:EWMultiColumnTableViewColumnPositionMiddle animated:YES];
    } afterDelay:0.5f];
    
    
    
}

//设置表格视图有多少个分区
-(NSInteger)numberOfSectionsInTableView:(EWMultiColumnTableView *)tableView
{
    return numberOfSections;
}


//为表格视图创建一个Label标签
-(UIView*)tableView:(EWMultiColumnTableView *)tableView cellForIndexPath:(NSIndexPath *)indexPath column:(NSInteger)col
{
    UILabel* l = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, colWidth, 40.0f)];
    l.numberOfLines = 0;
    l.lineBreakMode = NSLineBreakByWordWrapping;
    return l;
}

//为Cell中的Label标签赋值
-(void)tableView:(EWMultiColumnTableView *)tableView setContentForCell:(UIView *)cell indexPath:(NSIndexPath *)indexPath column:(NSInteger)col
{
    UILabel* l = (UILabel*)cell;
    l.text = [[[data objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectAtIndex:col];
    
    CGRect f = l.frame;
    f.size.width = [self tableView:tableView widthForColumn:col];
    l.frame = f;
    [l sizeToFit];
    
}


//数据区的高度
-(CGFloat)tableView:(EWMultiColumnTableView *)tableView heightForCellAtIndexPath:(NSIndexPath *)indexPath column:(NSInteger)column
{
    NSString* str = [[[data objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectAtIndex:column];
    CGSize s = [str sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] constrainedToSize:CGSizeMake([self tableView:tableView widthForColumn:column], MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
    return s.height + 20.0f;
    
    
}

//设置数据区Cell的宽度
-(CGFloat)tableView:(EWMultiColumnTableView *)tableView widthForColumn:(NSInteger)column
{
   // return colWidth;
    return 200;
    
}

//设置每个分区的个数
-(NSInteger)tableView:(EWMultiColumnTableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[data objectAtIndex:section] count];
}

//为数据区分区的头部添加一个Label
-(UIView*)tableView:(EWMultiColumnTableView *)tableView sectionHeaderCellForSection:(NSInteger)section column:(NSInteger)col
{
    UILabel* l = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [self tableView:tableView widthForColumn:col], 40.0f)];
    l.backgroundColor = [UIColor yellowColor];
    return l;
}

//设置数据区分区的头部Label赋值
-(void)tableView:(EWMultiColumnTableView *)tableView setContentForSectionHeaderCell:(UIView *)cell section:(NSInteger)section column:(NSInteger)col
{
    UILabel* l = (UILabel*)cell;
    l.text = [NSString stringWithFormat:@"S %d C %d",section,col];
    
    CGRect f = l.frame;
    f.size.width = [self tableView:tableView widthForColumn:col];
    l.frame = f;
    [l sizeToFit];
    
    
}

//设置数据区分区的列数
-(NSInteger)numberOfColumnsInTableView:(EWMultiColumnTableView *)tableView
{
    return numberOfColumns;
}

#pragma mark Header Cell

//为数据区左侧的Cell添加一个Label
- (UIView *)tableView:(EWMultiColumnTableView *)tableView headerCellForIndexPath:(NSIndexPath *)indexPath
{
    return [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 40.0f)] ;
}
//为数据区左侧的Cell的Label赋值
- (void)tableView:(EWMultiColumnTableView *)tableView setContentForHeaderCell:(UIView *)cell atIndexPath:(NSIndexPath *)indexPath
{
    UILabel *l = (UILabel *)cell;
    l.text = [NSString stringWithFormat:@"Line: (%d, %d)", indexPath.section, indexPath.row];
}

//设置左侧Cell的高度 为了保证左右的高度一致,所以在左侧与右侧相比较时,取最大值
- (CGFloat)tableView:(EWMultiColumnTableView *)tableView heightForHeaderCellAtIndexPath:(NSIndexPath *)indexPath
{
    return 40.0f;
}

//设置数据分区标题Cell的高度
- (CGFloat)tableView:(EWMultiColumnTableView *)tableView heightForSectionHeaderCellAtSection:(NSInteger)section column:(NSInteger)col
{
    return 50.0f;
}

//为数据分区标题添加一个Label
- (UIView *)tableView:(EWMultiColumnTableView *)tableView headerCellInSectionHeaderForSection:(NSInteger)section
{
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [self widthForHeaderCellOfTableView:tableView], 30.0f)] ;
    l.backgroundColor = [UIColor orangeColor];
    return l;
    
}

//为Label的标题赋值
- (void)tableView:(EWMultiColumnTableView *)tableView setContentForHeaderCellInSectionHeader:(UIView *)cell AtSection:(NSInteger)section
{
    UILabel *l = (UILabel *)cell;
    l.text = [NSString stringWithFormat:@"Section %d", section];
}

/*左侧头部标题的宽度*/
- (CGFloat)widthForHeaderCellOfTableView:(EWMultiColumnTableView *)tableView
{
    return 200.0f;
}

/*为右侧头部标题赋值*/
- (UIView *)tableView:(EWMultiColumnTableView *)tableView headerCellForColumn:(NSInteger)col
{
    UILabel *l =  [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 250.0f, 300.0f)] ;
    l.text = [NSString stringWithFormat:@"999Column: %d", col];
    l.userInteractionEnabled = YES;
    
    l.tag = col;
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)] ;
    recognizer.numberOfTapsRequired = 2;
    [l addGestureRecognizer:recognizer];
    
    return l;
}

/*为左侧头部标签赋值*/
- (UIView *)topleftHeaderCellOfTableView:(EWMultiColumnTableView *)tableView
{
    UILabel *l =  [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 250.0f, [self heightForHeaderCellOfTableView:tableView])] ;
    l.text = @"Products";
    
    return l;
}

/*总头部的高度*/
- (CGFloat)heightForHeaderCellOfTableView:(EWMultiColumnTableView *)tableView
{
    return 100.0f;
}

- (void)tableView:(EWMultiColumnTableView *)tableView swapDataOfColumn:(NSInteger)col1 andColumn:(NSInteger)col2
{
    for (int i = 0; i < [self numberOfSectionsInTableView:tableView]; i++) {
        NSMutableArray *section = [data objectAtIndex:i];
        for (int j = 0; j < [self tableView:tableView numberOfRowsInSection:i]; j++) {
            NSMutableArray *a = [section objectAtIndex:j];
            id tmp = [a objectAtIndex:col2] ;
            
            [a replaceObjectAtIndex:col2 withObject:[a objectAtIndex:col1]];
            [a replaceObjectAtIndex:col1 withObject:tmp];
           
        }
    }
}

- (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer
{
    int col = [recognizer.view tag];
    for (NSMutableArray *array in sectionHeaderData) {
        [array removeObjectAtIndex:col];
        //        [array addObject:@""];
    }
    
    for (NSMutableArray *section in data) {
        for (NSMutableArray *row in section) {
            [row removeObjectAtIndex:col];
            //            [row addObject:l@""];
        }
    }
    
    numberOfColumns--;
    
    [tbView reloadData];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end













《Tecplot与MIKE结合教程》是一份详细介绍如何将Tecplot与MIKE软件进行协同工作的学习资料。这份教程旨在帮助用户理解并掌握这两款强大的科学计算与数据可视化工具的整合应用,从而提高在流体动力学、环境工程、海洋科学等领域的模拟分析效率。 Tecplot是一款广泛应用于科研和工程领域的数据可视化和分析软件,它能够处理大量数据,快速生成高质量的2D和3D图形,便于用户理解和解释复杂的数值模拟结果。其强大的后处理能力,如等值线绘制、颜色梯度图、矢量场显示等功能,使得数据的呈现更加直观。 MIKE(原名DHI软件)是由丹麦水力研究所开发的一系列专业仿真软件,主要用于水资源管理、环境流动、海岸工程等领域。MIKE软件家族包括MIKE 11(河流模拟)、MIKE 21(海洋模型)、MIKE 3(三维流体动力学模型)等,可以解决从河流、湖泊到海洋的各类水动力问题。 当Tecplot与MIKE结合使用时,Tecplot作为后处理器,可以接收MIKE软件产生的计算结果,进行更深入的数据解析和可视化。通过这种方式,用户不仅可以查看MIKE模拟出的流场、浓度分布等数据,还能进行多变量分析、动画制作,以及生成专业报告所需的图表,极大地提高了数据分析的效率和质量。 教程中可能会涵盖以下内容: 1. **数据导入**:讲解如何从MIKE软件导出适合Tecplot处理的文件格式,如ASCII或二进制文件。 2. **Tecplot界面操作**:介绍Tecplot的基本操作,如数据加载、变量选择、区域定义等。 3. **数据可视化**:教学如何使用Tecplot创建等值线图、颜色梯度图、矢量图等,以及调整色彩映射、透明度等参数,以清晰地展示MIKE的模拟结果。 4. **动画制作**:说明如何通过Tecplot制作时间序列动画,动态展示流动过程。 5. **高级分析**:可能涉及统计分析、插值运算、剖面图绘制等高级功能,帮助用户深入理解模拟数据。 6. **定制化和脚本编程**:介绍如何利用Tecplot的内置脚本语言(如TecScript或Python)自动化处理MIKE数据,进行批量分析或自定义功能的实现。 7. **案例研究**:提供实际案例,演示Tecplot与MIKE结合的具体应用,如河流污染扩散分析、海岸线变化模拟等。 通过学习这份教程,用户将能够熟练地将Tecplot与MIKE结合使用,提升在复杂水动力问题上的建模和分析能力,为科学研究和工程决策提供有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杜甲同学

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值