zoukankan      html  css  js  c++  java
  • 简单tableView的使用

    UITableView是一个用于显示列表的视图,可以作为子视图镶嵌在主视图上,可以滑动,选取各种参数

    定义:

    @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{


    @property (nonatomic, retain) NSArray *dataList;

    @property (nonatomic, retain) UITableView *myTableView;


        UITableView *tableView = [[UITableViewalloc] initWithFrame:FRAME_TABLEVIEWstyle:UITableViewStylePlain];

    注意:这里的两个属性 dataList和myTableView并不要求实现,只需要在头文件定义就可以了

    Delegate必须要有,因为必须要实现它的接口

    使用:

        //init tableView

        NSArray *list = [NSArray arrayWithObjects:@"模糊",@"素描",@"怀旧", nil];

        self.dataList = list;

        // 设置tableView的数据源

        tableView.dataSource = self;

        // 设置tableView的委托

        tableView.delegate = self;

        // 设置tableView的背景图

    //    tableView.backgroundView = [[UIImageView alloc] init];

        self.myTableView = tableView;

        self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        [self.view addSubview:self.myTableView];

    常用的属性设置:

        //设置转置,使table view倒过来

        tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);

        //取消滑动出现删除

        tableView.showsVerticalScrollIndicator = NO;

    接口的实现:

     

    //set cells

    //定义每个列表项的属性

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

    {

        static NSString *CellWithIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];

        if (cell == nil) {

            cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellWithIdentifier];

        }

        cell.imageView.image = [UIImageimageNamed:@"example.png"];

        return cell;

    }

     

    //set number of sections

    //定义块的个数

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        return 1;

    }

     

    //行首缩进

    //定义首行缩进的宽度

    - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return 0;

    }

     

    //row height

    //定义每一行的高度

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return 105;

    }

     

     

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    {

    //    if ([indexPath row] % 2 == 0) {

    //        cell.backgroundColor = [UIColor blueColor];

    //    } else {

    //        cell.backgroundColor = [UIColor greenColor];

    //    }

    }

     

     

    //select rows callback

    //选择某行以后的动作方法

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        switch ([indexPath row]) {

            case 0:

                testFilter = [[GPUImageFastBlurFilteralloc] init];

                break;

            case 1:

                testFilter = [[GPUImageSketchFilteralloc] init];

                break;

            case 2:

                testFilter = [[GPUImageSepiaFilteralloc] init];

                break;

            default:

                break;

        } 

    }

     

     

    // delete

    //选择删除以后的方法

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

    {

        NSLog(@"执行删除操作");

    }

     

    //设置没有分界线

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

        returnUITableViewCellEditingStyleNone;

    }

     

     

    //number of rows

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        returnself.dataList.count;

    }

  • 相关阅读:
    Microsoft .NET Framework 2.0实现发送邮件(Email)总结
    Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总
    抽象类
    WingIDE 单步调试 Uliweb Python 代码
    Android 4.0 SDK的离线方式安装
    .NET 3.5 中WCF客户端代理性能改进以及最佳实践
    在linux上部署Redmine
    认识jQuery mobile 框架,资源,书籍
    如何使用搜索技巧来成为一名高效的程序员
    Management Console 工具管理类软件通用开发框架(开放源码)
  • 原文地址:https://www.cnblogs.com/wisejoker/p/3399835.html
Copyright © 2011-2022 走看看