使用EWMultiColumnTableView第三库

最近项目需要需要使用类似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













深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
【6层】4837.9平米六层框架综合办公楼(含计算书、建筑、结构图纸) 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

杜甲同学

感谢打赏,我会继续努力

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

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

打赏作者

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

抵扣说明:

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

余额充值