iOS 上非常好用的表单工具。兼容swift
和OC
参考 XLForm
RETableViewManager
以及swift库 Eureka
由于平台审核原因,请giithub
自己搜索YIForm
以下为内部结构图:
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