iOS实现表格(非TableView)

WhdeForm

iOS 表格项目地址:https://github.com/whde/WhdeForm

pod ‘WhdeForm‘, ‘~> 1.0.0‘
  • 添加了Reusable机制
  • 添加了横(Section)表头
  • 添加了竖(Column)表头
  • 添加了左上角(TopLeftHeader)总表头
  • 通过FDateSource去创建各个元素,类似TableView
  • 添加了FIndexPath,{section, column}
  • 表头添加点击事件
  • 添加了网格

使用

#import "ViewController.h"
#import "FormScrollView.h"
@interface ViewController ()<FDelegate, FDataSource> {
    NSArray *_data;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.autoresizingMask = UIViewAutoresizingNone;
    FormScrollView *table = [[FormScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64)];
    table.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    table.fDelegate = self;
    table.fDataSource = self;
    [self.view addSubview:table];

    _data = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"datas" ofType:@"plist"]];
    [table reloadData];
}
- (FTopLeftHeaderView *)topLeftHeadViewForForm:(FormScrollView *)formScrollView {
    FTopLeftHeaderView *view = [formScrollView dequeueReusableTopLeftView];
    if (view == NULL) {
        view = [[FTopLeftHeaderView alloc] initWithSectionTitle:@"行数" columnTitle:@"列数"];
    }
    return view;
}

- (NSInteger)numberOfSection:(FormScrollView *)formScrollView {
    return _data.count;
}
- (NSInteger)numberOfColumn:(FormScrollView *)formScrollView {
    return 100;
}
- (CGFloat)heightForSection:(FormScrollView *)formScrollView {
    return 44;
}
- (CGFloat)widthForColumn:(FormScrollView *)formScrollView {
    return 80;
}
- (FormSectionHeaderView *)form:(FormScrollView *)formScrollView sectionHeaderAtSection:(NSInteger)section {
    FormSectionHeaderView *header = [formScrollView dequeueReusableSectionWithIdentifier:@"Section"];
    if (header == NULL) {
        header = [[FormSectionHeaderView alloc] initWithIdentifier:@"Section"];
    }
    [header setTitle:[NSString stringWithFormat:@"第%ld行", (long)section] forState:UIControlStateNormal];
    /*[header setBackgroundColor:[UIColor redColor]];*/
    [header setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    return header;
}
- (FormColumnHeaderView *)form:(FormScrollView *)formScrollView columnHeaderAtColumn:(NSInteger)column {
    FormColumnHeaderView *header = [formScrollView dequeueReusableColumnWithIdentifier:@"Column"];
    if (header == NULL) {
        header = [[FormColumnHeaderView alloc] initWithIdentifier:@"Column"];
    }
    [header setTitle:[NSString stringWithFormat:@"第%ld列", (long)column] forState:UIControlStateNormal];
    /*[header setBackgroundColor:[UIColor greenColor]];*/
    [header setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    return header;
}
- (FormCell *)form:(FormScrollView *)formScrollView cellForColumnAtIndexPath:(FIndexPath *)indexPath {
    FormCell *cell = [formScrollView dequeueReusableCellWithIdentifier:@"Cell"];
    NSLog(@"%@", cell);
    if (cell == NULL) {
        cell = [[FormCell alloc] initWithIdentifier:@"Cell"];
        static int i=0;
        i++;
        NSLog(@"%d--%ld", i, (long)indexPath.section);
    }
    NSDictionary *dic = [_data objectAtIndex:indexPath.section];
    [cell setTitle:dic[@"name"] forState:UIControlStateNormal];
    [cell setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    /*[cell setBackgroundColor:[UIColor yellowColor]];*/
    return cell;
}
- (void)form:(FormScrollView *)formScrollView didSelectSectionAtIndex:(NSInteger)section {
    NSLog(@"Click Section At Index:%ld", (long)section);
}
- (void)form:(FormScrollView *)formScrollView didSelectColumnAtIndex:(NSInteger)column {
    NSLog(@"Click Cloumn At Index:%ld", (long)column);
}
- (void)form:(FormScrollView *)formScrollView didSelectCellAtIndexPath:(FIndexPath *)indexPath {
    NSLog(@"Click Cell At IndexPath:%ld,%ld", (long)indexPath.section, (long)indexPath.column);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
时间: 2024-07-29 15:31:32

iOS实现表格(非TableView)的相关文章

iOS中表格(UITableView)嵌套表格的简单实现

iOS中表格(UITableView)嵌套表格的简单实现 首先说一下思路:我们在一个控制器里面定义2个tableview,一个作为被嵌套的rootTable,一个作为嵌套的表格tableView1,那我们要实现UITableViewDelegate,UITableViewDataSource,的代理的时候,该怎么区分呢?其实很简单,有两种方法,一个是给定义的2个tableview设置tag值,另一个是直接写出来tableView == rootTable时实现他得代理,否则就实现tableVie

IOS 取消表格单元格 TableViewCell 去掉高亮状态 点击Cell取消选择状态

以下是两种实现效果 1. 自定义cell 继承UITableViewCell 重写 -(void)setSelected:(BOOL)selected animated:(BOOL)animated { } -(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { } 里面不写任何东西 注意重写的时候一定要有带animated 方法,不然还是无效 2.点击单元格 取消选中单元格 //  点击单元格的时候取消选中单元格 -(

iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见

iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见 (2015-12-05 12:48:20)[编辑][删除] 转载▼     首先我们先明确一下问题: 1.因为UI是在主线程中更新的,不能在down数据的同时显示界面,这样会使得下载的时间占用主线程,导致的后果就是你的屏幕就那样的卡死在哪了 2.如果要解觉问题1,就势必要将其下载数据的环节放在其他分线程上来实现,但是这里还会遇见一个问题,分线程的执行是不会有序的,这样,在动态显示的过 程中,cell中的数据就会混乱的变

IOS ARC和非ARC文件混用

ARC在SDK4.0的时候加入的,由于要和以前的项目融合,就会有arc和非arc文件的混合. 当然,也就这两种情况: 1.自己的旧项目没有使用ARC,但是引入的第三方库却是使用了ARC的. 2.自己的新项目使用了ARC,但是引入代码却没有使用ARC. 这两种情况下,直接肯定是通不过编译的.可以通过升级旧项目,让其使用ARC来解决,但这个办法有时候会很麻烦. 有一个简单的办法就是,可以指定单个文件是否采用ARC来进行编译. 方法就是在Build Phase里面的Compile Source里面找到

iOS-表格数据的添加 删除

// // ViewController.m // 表格的修改 // // Created by YaguangZhu on 15/8/16. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "ViewController.h" @interface ViewController ()<UITabBarControllerDelegate> @property (nonatomic,str

IOS UITableView表格视图详解

IOS 表格视图类UITableView 实现的协议:UITableViewDataSource,UITableViewDelegate 必须实现下面的3个方法: - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView { return 1; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {

iOS开发-UI (八)TableView

知识点: 1.UITableView使用 2.UITableView分段功能 3.UITableViewCell重用机制 ======================= UITableView使用 1.UITableView作用 2.UITableView创建 - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style; UITableViewStyle: UITableViewStylePlain       列表模式 UIT

iOS:UITableView表格视图控件

UITableView:表格视图控件,继承滚动视图控件UIScrollView,(类似于UIPickerView选择器,它主要通过设置数据源代理和行为代理实现协议来设置单元格) 对表格的操作主要有:创建表格.设置单元格(行数.内容.行高).编辑单元格(删除单元格.插入单元格).移动单元格.标记单元格.修改单元格等. 一.表格式图的属性和行为: 1.基本属性: @interface UITableView : UIScrollView <NSCoding> @property (nonatomi

iOS开发——UI_swift篇&amp;TableView实现页眉和页脚

TableView实现页眉和页脚 UITableView具有var tableHeaderView:UIView?属性和var tableFooterView:UIView?属性,可以通过给其赋值来创建列表TableView的页眉和页脚. 效果图如下: 代码如下: 1 import UIKit 2 3 class ViewController: UIViewController,UITableViewDelegate, 4 UITableViewDataSource,UIGestureRecog