YIForm iOS平台定制表单,轻量级,好用好用

iOS 上非常好用的表单工具。兼容swiftOC
参考 XLForm RETableViewManager以及swift库 Eureka
由于平台审核原因,请giithub自己搜索YIForm

屏幕录制2021-04-27 下午4.49.52.2021-04-27 17_09_21.gif

以下为内部结构图:


1.png

YIFormManager

//
//  YIFormManager.h
//  YIForm
//
//  Created by Yilia on 2020/10/12.
//

#import <Foundation/Foundation.h>
#import "YIFormMacro.h"

NS_ASSUME_NONNULL_BEGIN

/// 创建 section
FOUNDATION_EXPORT YIFormSection *Section(void);
/// 创建 row
/// @param rowClass row class
FOUNDATION_EXPORT __kindof YIFormRow *Row(id rowClass);


typedef NS_ENUM(NSUInteger, XLPredicateType) {
    XLPredicateTypeDisabled = 0,
    XLPredicateTypeHidden
};

@interface YIFormManager : NSObject
// 默认 NO
@property (nonatomic) BOOL disabled;
/// 对应tableView
@property (nullable, weak, nonatomic, readonly) UITableView *tableView;

/// sections
@property (strong, nonatomic, readonly) NSArray<__kindof YIFormSection *> *sections;
/// 初始化方法
/// @param tableView  tableView
+ (instancetype)managerForTableView:(UITableView *)tableView;

/// 初始化方法
/// @param tableView  tableView
- (instancetype)initWithTableView:(UITableView *)tableView;


// MARK: - 刷新

/// 重新加载 sections
/// @param sections section 数组
- (void)reloadSections:(NSArray<YIFormSection *> *)sections;
/// 重新加载
/// @param rows row 数组
- (void)reloadRows:(NSArray<YIFormRow *> *)rows;

/// 重新加载 sections
/// @param indexes indexes
- (void)reloadSectionsAt:(NSIndexSet *)indexes;

/// 重新加载
/// @param indexPaths indexPaths
- (void)reloadRowsAt:(NSArray<NSIndexPath *> *)indexPaths;

// MARK: - 检索
/// <#Description#>
/// @param row <#row description#>
-(NSIndexPath *)indexPathForRow:(YIFormRow *)row;

-(NSUInteger)indexForSection:(YIFormSection *)section;
///
/// tag 对应 section
/// @param tag section tag
- (nullable YIFormSection *)sectionWithTag:(NSString *)tag;
/// tag 对应 row
/// @param tag row tag
- (nullable __kindof YIFormRow *)rowWithTag:(NSString *)tag;

/// indexPath 对应的 row
/// @param indexPath indexPath
- (nullable __kindof YIFormRow *)rowAtIndexPath:(NSIndexPath *)indexPath;
// MARK: - 增 删

/// 添加 sections
/// @param sections section 数组
- (void)addSections:(NSArray<YIFormSection *> *)sections;
/// 移除 sections
/// @param sections section 数组
- (void)removeSections:(NSArray<YIFormSection *> *)sections;
/// 移除indexes 对应的 sections
/// @param indexes index 数组
- (void)removeSectionsAt:(NSIndexSet *)indexes;

/// 移除所有
- (void)removeAll;

/// 移除 row
/// @param formRow row
-(void)removeRow:(YIFormRow *)formRow;

/// 移除 tag 对应的 row
/// @param tag row tag
-(void)removeRowWithTag:(nonnull NSString *)tag;

// MARK: -

/// @param formRow formRow
/// @param oldValue oldValue
/// @param newValue newValue
-(void)formRowValueHasChanged:(YIFormRow *)formRow oldValue:(id)oldValue newValue:(id)newValue;

/// 更新ui
/// @param rows
- (void)displayRows:(NSArray<YIFormRow *> *)rows;

@end

NS_ASSUME_NONNULL_END

YIFormSection

//
//  YIFormSection.h
//  YIForm
//
//  Created by Yilia on 2020/10/12.
//

#import <Foundation/Foundation.h>
#import "YIFormRow.h"

extern CGFloat const YIFormSectionHeaderHeightAutomatic;
extern CGFloat const YIFormSectionFooterHeightAutomatic;

@class YIFormManager;
NS_ASSUME_NONNULL_BEGIN

@interface YIFormSection : NSObject
/// 默认 NO
@property (nonatomic, assign) BOOL disabled;
///
@property (strong, nonatomic, nullable) NSString *tag;
/// 对应的rows
@property (strong, nonatomic, readonly) NSArray<__kindof YIFormRow *> *rows;
/**
 A view object to display in the header of the specified section of the table view.
 */
@property (strong, readwrite, nonatomic) UIView *headerView;

/**
 A view object to display in the footer of the specified section of the table view.
 */
@property (strong, readwrite, nonatomic) UIView *footerView;

/**
 The height of the header of the specified section of the table view.
 */
@property (assign, readwrite, nonatomic) CGFloat headerHeight;

/**
 The height of the footer of the specified section of the table view.
 */
@property (assign, readwrite, nonatomic) CGFloat footerHeight;
/**
 Section index in UITableView.
 */
@property (assign, readonly, nonatomic) NSUInteger index;

/// section 圆 半径
@property (nonatomic) CGFloat cornerRadius;

/// cell 内容与边缘间距
@property (nonatomic, assign) CGFloat horizontalInset;

/// 对应的 formManager
@property (nonatomic, weak, null_unspecified) YIFormManager * formManager;

/// 添加 rows
/// @param rows 数组
- (void)addRows:(NSArray<YIFormRow *> *)rows;

/// 删除rows
/// @param rows 数组
- (void)removeRows:(NSArray<YIFormRow *> *)rows;

/// 删除对应的indexes 的rows
/// @param indexes 数组
- (void)removeRowsAt:(NSIndexSet *)indexes;

/// 在 index 处插入 row
/// @param row row
/// @param index index
- (void)insertRow:(YIFormRow *)row at:(NSInteger)index;

/// tags 对应的row
/// @param tags tags 数组
- (NSArray<__kindof YIFormRow *> *)rowsWithTags:(NSArray<NSString *> *)tags;

/// tag 对应的row
/// @param tag tag
- (nullable __kindof YIFormRow *)rowWithTag:(NSString *)tag;

/// 刷新
- (void)reload;
+ (instancetype)section;
@end

NS_ASSUME_NONNULL_END

YIFormRow

//
//  YIFormRow.h
//  YIForm
//
//  Created by Yilia on 2020/10/12.
//

#import <Foundation/Foundation.h>
#import "YIFormCell.h"
@class YIFormAction;
@class YIFormSection;
NS_ASSUME_NONNULL_BEGIN

extern CGFloat YIFormRowInitialHeight;

typedef void(^YIOnChangeBlock)(id __nullable oldValue, id __nullable newValue, YIFormRow * row);

@interface YIFormRow : NSObject

//@property(nonatomic) BOOL hidden;
/// 是否 disabled 默认NO
@property (nonatomic) BOOL disabled;
/// 是否 required 默认NO
@property (nonatomic) BOOL required;

///
@property (nullable, strong, nonatomic) NSString *tag;

/// title
@property (nullable, nonatomic, copy) NSString *title;

/// 对应的cell
@property (nonnull, strong, nonatomic, readonly) Class cellClass;
/// 当前cellclass
@property (strong, nonatomic, readonly) Class currentCellClass;
/// 值
@property(nonatomic, strong, nullable) id value;

/// 行高 default is 44.0f
@property (nonatomic, assign) CGFloat height;
/// cell 内缩进
@property (nonatomic, assign) UIEdgeInsets contentEdgeInsets;
/// 分割线 左 缩进
@property (nonatomic) CGFloat separatorLeftInset;
/// 分割线 右 缩进
@property (nonatomic) CGFloat separatorRightInset;
/// 自动刷新 默认 NO
@property (nonatomic) BOOL autoRefresh;
// XLForm

@property (nonatomic, assign  ) UITableViewCellStyle cellStyle;

@property (nonatomic, copy, nullable) YIOnChangeBlock onChangeBlock;

@property (nonatomic, strong) NSMutableDictionary * cellConfig;
//@property (nonatomic, strong) NSMutableDictionary * cellConfigForSelector;
@property (nonatomic, strong) NSMutableDictionary * cellConfigIfDisabled;
@property (nonatomic, strong) NSMutableDictionary * cellConfigAtConfigure;

// RETableViewManager
///
@property (strong, nonatomic) UIColor *containerBackgroundColor;
///
@property (nullable, strong, nonatomic) UIColor *separatorColor;
@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle;
@property (assign, readwrite, nonatomic) UITableViewCellSelectionStyle selectionStyle;
@property (assign, readwrite, nonatomic) UITableViewCellAccessoryType accessoryType;
@property (assign, readwrite, nonatomic) UITableViewCellEditingStyle editingStyle;
@property (strong, readwrite, nonatomic) UIView *accessoryView;

@property (copy, nonatomic) void (^selectionHandler)(__kindof YIFormRow *item);

@property (copy, nonatomic) void (^accessoryButtonTapHandler)(__kindof YIFormRow *item);
@property (copy, nonatomic) void (^insertionHandler)(__kindof YIFormRow *item);
// deletionHandler deletionHandlerWithCompletion 配置 二选一
@property (copy, nonatomic) void (^deletionHandler)(__kindof YIFormRow *item);
@property (copy, nonatomic) void (^deletionHandlerWithCompletion)(__kindof YIFormRow *item, void (^)(void));
@property (copy, readwrite, nonatomic) BOOL (^moveHandler)(YIFormRow *item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath);
@property (copy, readwrite, nonatomic) void (^moveCompletionHandler)(YIFormRow *item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath);
@property (copy, readwrite, nonatomic) void (^cutHandler)(__kindof YIFormRow *item);
@property (copy, readwrite, nonatomic) void (^copyHandler)(__kindof YIFormRow *item);
@property (copy, readwrite, nonatomic) void (^pasteHandler)(__kindof YIFormRow *item);

/// row 对应 indexPath
@property (strong, nonatomic, readonly) NSIndexPath *indexPath;
/// row 对应的cell
@property (strong, nonatomic, readonly) __kindof YIFormCell *cell;
/// row 所在section
@property (nonatomic, weak, null_unspecified) YIFormSection *section;

- (void)reload;

/// special cell class init
/// @param cellClass subclass of YIFormCell
- (instancetype)initWithCellClass:(Class)cellClass;

+ (instancetype)row;

+ (instancetype)rowWithCellClass:(Class)cellClass;

+ (instancetype)rowWithContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets;

+ (instancetype)rowWithCellClass:(nullable Class)cellClass title:(nullable NSString *)title value:(NSString *)value contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets;
@end

NS_ASSUME_NONNULL_END

YIFormCell

//
//  YIFormCell.h
//  YIForm
//
//  Created by Yilia on 2020/10/12.
//

#import <UIKit/UIKit.h>

@class YIFormRow;

NS_ASSUME_NONNULL_BEGIN
@protocol YIFormCellProtocol <NSObject>

@required



//-(BOOL)formDescriptorCellCanBecomeFirstResponder;
//-(BOOL)formDescriptorCellBecomeFirstResponder;
//-(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller;

//-(void)highlight;

//-(void)unhighlight;




@end

@interface YIFormCell : UITableViewCell<YIFormCellProtocol>
@property (strong, nonatomic, readonly) UIView *containerView;
///
//@property (nonnull, strong, nonatomic, readonly) UIView *customContentView;
///
@property (strong, nonatomic) UIColor *separatorColor;
@property (nonatomic, weak) __kindof YIFormRow * row;

/// top 距 tableview 缩进
@property (nonatomic, readonly) CGFloat topMargin;
/// left 距 tableview 缩进
@property (nonatomic, readonly) CGFloat leftMargin;

/// right 距 tableview 缩进
@property (nonatomic, readonly) CGFloat rightMargin;

/// bottom 距 tableview 缩进
@property (nonatomic, readonly) CGFloat bottomMargin;
/// 分割线 左 距 tableview 缩进
@property (nonatomic, readonly) CGFloat separatorLeftMargin;

/// 分割线 右 距 tableview 缩进
@property (nonatomic, readonly) CGFloat separatorRightMargin;

/// 初始化配置 添加UI 布局等
-(void)configure;

/// 更新数据 或 UI布局
-(void)update;

@end

NS_ASSUME_NONNULL_END

demo

//
//  YIViewController.m
//  YIForm
//
//  Created by yiliazhang on 10/12/2020.
//  Copyright (c) 2020 yiliazhang. All rights reserved.
//

#import "YIViewController.h"
#import <YIForm/YIForm.h>
#import "YIAttachFormRow.h"
#import "YIFormRowText.h"
#import <Masonry/Masonry.h>
#import "GWAuthInfoCell.h"
#import "YIFormTextCell.h"
#import "YIMessageViewController.h"

@interface YIViewController ()<UIDocumentPickerDelegate, UIDocumentInteractionControllerDelegate>
///
@property (nonnull, strong, nonatomic) YIFormManager *formManager;
///
@property (nonnull, strong, nonatomic) UITableView *tableView;
/// tag
@property (nonatomic, copy) NSString *currrentFileUploadRowTag;


// Deletable items with confirmation

@property (strong, readwrite, nonatomic) YIFormRow *itemToDelete;
@property (copy, readwrite, nonatomic) void (^deleteConfirmationHandler)(void);

@end

@implementation YIViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(switchTableEdit:)];
    
    self.tableView.frame = self.view.bounds;
    [self.view addSubview:self.tableView];
    // Do any additional setup after loading the view, typically from a nib.
    self.formManager = [YIFormManager managerForTableView:self.tableView];
    [self refreshAction:nil];
}

- (IBAction)refreshAction:(id)sender {
    [self.formManager removeAll];
    NSArray *sections = @[
        [self accessoryTypeSection],
        [self specialCellClassSection],
        [self customAccessorySection],
        [self randomSection],
        [self deletableSection],
        [self deleteConfirmSection],
        [self insertSection],
        [self movableSection],
        [self movableAndDeletableSection],
        [self copyCutPastSection],
    ];
    [self.formManager addSections:sections];
    [self.tableView reloadData];
}

- (IBAction)removeAction:(id)sender {
    
}
- (void)switchTableEdit:(UIBarButtonItem *)sender {
    self.editing = !self.editing;
    self.tableView.editing = self.editing;
    [sender setTitle:self.editing ? @"完成" : @"编辑"];
}

- (YIFormSection *)randomSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        //        __weak typeof(self) weakSelf = self;
        NSString *title = [NSString stringWithFormat:@"random %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
//        YIFormRow *row = [self telephoneRow];
        if (r == 1) {
            row.disabled = YES;
            row.separatorStyle = UITableViewCellSeparatorStyleNone;
            row.title = @"disabled - random";
        }
                row.contentEdgeInsets = UIEdgeInsetsMake(20, 40, 10, 30);
        row.separatorLeftInset = 20;
        row.separatorRightInset = 20;
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    section.headerHeight = 20;
    section.footerHeight = 20;
    [section addRows:rows];
    section.cornerRadius = 20;
    section.horizontalInset = 50;
    return section;
}


- (YIFormSection *)customAccessorySection {
    // 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        NSString *title = [NSString stringWithFormat:@"customAccessory %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        UIButton *button = [[UIButton alloc] init];
        button.frame = CGRectMake(0, 0, 50, 30);
        [button setTitle:@"点击" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(accessoryButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.backgroundColor = [UIColor blackColor];
        row.accessoryView = button;
        
        [rows addObject:row];
        r++;
    }
    
    YIFormSection *section = Section();
    [section addRows:rows];
    section.headerView = [self headerViewWithTitle:@" custom Accessory \r\n 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset"];
    section.footerView = [self footerView];
    
    return section;
}

- (YIFormSection *)accessoryTypeSection {
    // 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        NSString *title = [NSString stringWithFormat:@"accessoryType %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        row.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        row.accessoryButtonTapHandler = ^(__kindof YIFormRow * _Nonnull item) {
            NSLog(@"accessoryButtonTapHandler");
        };
        [rows addObject:row];
        r++;
    }
    
    YIFormSection *section = Section();
    [section addRows:rows];
    section.headerView = [self headerViewWithTitle:@"accessoryType \r\n 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset"];
    section.footerHeight = 20;
    return section;
}

- (YIFormSection *)specialCellClassSection {
    // 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        NSString *title = [NSString stringWithFormat:@"accessoryType %d", r];
        YIFormRow *row = [self rowWithTitle:title specialCellClass:[YIFormTextCell class]];
        row.title = @"asfasf";
        row.value = @"dddd";
        row.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        row.accessoryButtonTapHandler = ^(__kindof YIFormRow * _Nonnull item) {
            NSLog(@"accessoryButtonTapHandler");
        };
        [rows addObject:row];
        r++;
    }
    
    YIFormSection *section = Section();
    [section addRows:rows];
    section.headerView = [self headerViewWithTitle:@"accessoryType \r\n 有accesoryView 的情况下就不要设置 contentEdgeMargins 或 horizontalInset"];
    section.footerHeight = 20;
    return section;
}

- (YIFormSection *)insertSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        //        __weak typeof(self) weakSelf = self;
        NSString *title = [NSString stringWithFormat:@"insert %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        
        if (r == 1) {
            row.disabled = YES;
            row.title = @"disabled - insert";
        }
        row.insertionHandler = ^(YIFormRow *item) {
            NSLog(@"Insertion handler callback");
        };
        row.editingStyle = UITableViewCellEditingStyleInsert;
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    section.headerView = [self headerViewWithTitle:@"insert 功能"];
    section.footerHeight = 20;
    [section addRows:rows];
    return section;
}

- (YIFormSection *)movableSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 3;
    while (r < maxRow) {
        //        __weak typeof(self) weakSelf = self;
        NSString *title = [NSString stringWithFormat:@"movable %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        row.moveHandler = ^BOOL(id item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath) {
            return YES;
        };
        row.moveCompletionHandler = ^(YIFormRow *item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath) {
            NSLog(@"Moved item: %@ from [%li,%li] to [%li,%li]", item.title, (long) sourceIndexPath.section, (long) sourceIndexPath.row, (long) destinationIndexPath.section, (long) destinationIndexPath.row);
        };
        if (r == 1) {
            row.disabled = YES;
            row.title = @"disabled - movable";
        }
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    section.headerView = [self headerViewWithTitle:@"move 功能"];
    section.footerHeight = 20;
    [section addRows:rows];
    return section;
}

- (YIFormSection *)deletableSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 7;
    while (r < maxRow) {
        //        __weak typeof(self) weakSelf = self;
        NSString *title = [NSString stringWithFormat:@"deletable %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        
        if (r == 1) {
            row.disabled = YES;
            row.title = @"disabled - deletable";
            row.separatorColor = [UIColor greenColor];
        } else if (r == 2) {
            
            row.separatorColor = [UIColor blackColor];
        } else if (r == 3) {
            row.separatorColor = [UIColor clearColor];
        } else if (r == 4) {
            row.separatorColor = [UIColor blueColor];
        } else {
            row.separatorStyle = UITableViewCellSeparatorStyleNone;
        }
        row.contentEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 20);
        row.separatorLeftInset = 5;
        row.separatorRightInset = 20;
        
        row.editingStyle = UITableViewCellEditingStyleDelete;
        row.deletionHandler = ^(YIFormRow *item) {
            NSLog(@"Item removed: %@", item.title);
        };
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    [section addRows:rows];
    section.cornerRadius = 10;
    section.horizontalInset = 20;
    return section;
}

- (YIFormSection *)deleteConfirmSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 1;
    while (r < maxRow) {
        __weak typeof(self) weakSelf = self;
        NSString *title = [NSString stringWithFormat:@"deleteConfirm %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        row.editingStyle = UITableViewCellEditingStyleDelete;
        row.deletionHandlerWithCompletion = ^(YIFormRow *item, void (^completion)(void)) {
            [weakSelf showAlert:item];
            weakSelf.itemToDelete = item;
            // Assign completion block to deleteConfirmationHandler for future use
            weakSelf.deleteConfirmationHandler = completion;
        };
        
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    section.headerView = [self headerViewWithTitle:@"delete 删除功能"];
    section.footerHeight = 20;
    [section addRows:rows];
    return section;
}

- (YIFormSection *)movableAndDeletableSection {
    NSMutableArray *rows = [NSMutableArray array];
    int r = 0;
    int maxRow = 2;
    while (r < maxRow) {
        NSString *title = [NSString stringWithFormat:@"movableAndDeletable %d", r];
        YIFormRow *row = [self rowWithTitle:title tag:title];
        row.editingStyle = UITableViewCellEditingStyleDelete;
        
        row.moveHandler = ^BOOL(id item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath) {
            return YES;
        };
        row.moveCompletionHandler = ^(YIFormRow *item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath) {
            NSLog(@"Moved item: %@ from [%li,%li] to [%li,%li]", item.title, (long) sourceIndexPath.section, (long) sourceIndexPath.row, (long) destinationIndexPath.section, (long) destinationIndexPath.row);
        };
        [rows addObject:row];
        r++;
    }
    YIFormSection *section = Section();
    section.headerView = [self headerViewWithTitle:@"move delete 功能"];
    section.headerHeight = 20;
    section.footerHeight = 20;
    [section addRows:rows];
    return section;
}


- (YIFormSection *)copyCutPastSection {
    YIAttachFormRow *copyItem = [[YIAttachFormRow alloc] init];
    copyItem.title = @"copy";
    copyItem.selectionHandler = ^(__kindof YIFormRow * _Nonnull item) {
        //        [item deselectRowAnimated:YES];
    };
    copyItem.copyHandler = ^(YIFormRow *item) {
        [UIPasteboard generalPasteboard].string = @"Copied item #1";
    };
    
    
    YIAttachFormRow *pasteItem = [[YIAttachFormRow alloc] init];
    pasteItem.title = @"paste";
    pasteItem.selectionHandler = ^(__kindof YIFormRow * _Nonnull item) {
        //        [item deselectRowAnimated:YES];
    };
    pasteItem.pasteHandler = ^(YIFormRow *item) {
        item.title = [UIPasteboard generalPasteboard].string;
        [item reload];
    };
    
    YIAttachFormRow *cutCopyPasteItem = [[YIAttachFormRow alloc] init];
    cutCopyPasteItem.title = @"paste";
    cutCopyPasteItem.copyHandler = ^(YIFormRow *item) {
        [UIPasteboard generalPasteboard].string = @"Copied item #3";
    };
    cutCopyPasteItem.pasteHandler = ^(YIFormRow *item) {
        item.title = [UIPasteboard generalPasteboard].string;
        [item reload];
    };
    cutCopyPasteItem.cutHandler = ^(YIFormRow *item) {
        item.title = @"(Empty)";
        [UIPasteboard generalPasteboard].string = @"Copied item #3";
        //        [item reload];
    };
    
    YIFormSection *section = Section();
    section.headerView = [self headerViewWithTitle:@"copy cut paste 功能"];
    section.disabled = self.tableView.editing;
    section.headerHeight = 20;
    section.footerHeight = 20;
    [section addRows:@[copyItem, pasteItem, cutCopyPasteItem]];
    return section;
}

- (UIView *)headerViewWithTitle:(NSString *)title {
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = [UIColor redColor];
    headerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 100);
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 20, 5)];
    [headerView addSubview:label];
    label.text = title;
    label.numberOfLines = 0;
    
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:@"点" forState:UIControlStateNormal];
    
    
    return headerView;
}

- (UIView *)footerView {
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor orangeColor];
    footerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 5);
    return footerView;
}
- (__kindof YIFormRow *)telephoneRow {
    GWAuthInfoRow *row2 = [[GWAuthInfoRow alloc] init];
    row2.selectionStyle = UITableViewCellSelectionStyleNone;
    row2.message = @"您提交的认证信息未通过审核,请修订、完善";
    row2.tip = @"对结果有疑问请致电:020-12231232";
    return row2;
}

- (__kindof YIFormRow *)rowWithTitle:(NSString *)title tag:(NSString *)tag {
    //    YIFormRowText *row00 = Row(YIFormRowText.class);
    //    row00.height = arc4random()%50 + 10;
    //    row00.title = [NSString stringWithFormat:@"%@ height:%.2f",title, row00.height];
    //    Row(YIAttachFormRow.class)
    __weak typeof(self) weakSelf = self;
    YIAttachFormRow *row = [YIAttachFormRow row];
    row.tag = tag;
    row.title = title;
    row.containerBackgroundColor = [UIColor orangeColor];
    row.previewBlock = ^(NSURL *fileURL) {
    };
    
    row.uploadBlock = ^(NSURL *fileURLs) {
    };
    
    row.selectionHandler = ^(__kindof YIFormRow * _Nonnull item) {
        NSLog(@"selectionHandler");
    };
    
    return row;
}
- (__kindof YIFormRow *)rowWithTitle:(NSString *)title specialCellClass:(id)cellClass {
    //    YIFormRowText *row00 = Row(YIFormRowText.class);
    //    row00.height = arc4random()%50 + 10;
    //    row00.title = [NSString stringWithFormat:@"%@ height:%.2f",title, row00.height];
    //    Row(YIAttachFormRow.class)
    __weak typeof(self) weakSelf = self;
    YIAttachFormRow *row = [YIAttachFormRow rowWithCellClass:cellClass];
    row.title = title;
    row.containerBackgroundColor = [UIColor whiteColor];
//    row.containerBackgroundColor = [UIColor orangeColor];
    row.previewBlock = ^(NSURL *fileURL) {
    };
    
    row.uploadBlock = ^(NSURL *fileURLs) {
    };
    
    row.selectionHandler = ^(__kindof YIFormRow * _Nonnull item) {
        NSLog(@"selectionHandler");
    };
    
    return row;
}
- (void)accessoryButtonAction:(id)sender {
    __weak typeof(self) weakSelf = self;
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"点击" message:[NSString stringWithFormat:@"Hello,你点到我了"] preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        YIMessageViewController *viewController = [[YIMessageViewController alloc] init];
        [viewController showOnViewController:weakSelf];
    }];
    // Add the actions.
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
}


- (void)showAlert:(YIFormRow *)item {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirmation" message:[NSString stringWithFormat:@"Are you sure you want to delete %@", item.title] preferredStyle:UIAlertControllerStyleAlert];
    
    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        if (self.deleteConfirmationHandler) {
            self.deleteConfirmationHandler();
            NSLog(@"Item removed: %@", self.itemToDelete.title);
        }
    }];
    // Add the actions.
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    [self.navigationController presentViewController:alertController animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView {
    if (!_tableView) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView = tableView;
    }
    return _tableView;
}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,311评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,339评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,671评论 0 342
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,252评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,253评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,031评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,340评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,973评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,466评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,937评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,039评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,701评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,254评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,259评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,485评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,497评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,786评论 2 345

推荐阅读更多精彩内容

  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,523评论 28 53
  • 信任包括信任自己和信任他人 很多时候,很多事情,失败、遗憾、错过,源于不自信,不信任他人 觉得自己做不成,别人做不...
    吴氵晃阅读 6,181评论 4 8
  • 怎么对待生活,它也会怎么对你 人都是哭着来到这个美丽的人间。每个人从来到尘寰到升入天堂,整个生命的历程都是一本书,...
    静静在等你阅读 4,957评论 1 6