tableView中的cell复制粘贴操作
来源:互联网 发布:无法登录战网检查网络 编辑:程序博客网 时间:2024/06/08 18:56
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end
@implementation ViewController
- (NSMutableArray *)dataArray {
if (nil ==_dataArray) {
_dataArray = [NSMutableArrayarray];
NSString *path = [[NSBundlemainBundle]pathForResource:@"heros.plist"ofType:nil];
NSArray *tempArray = [NSArrayarrayWithContentsOfFile:path];
for (NSDictionary *dictin tempArray) {
HerosModel *model = [HerosModelHerosModelWithDictionary:dict];
[_dataArray addObject:model];
}
}
return_dataArray;
}
- (void)viewDidLoad {
[superviewDidLoad];
_tableView = [[UITableViewalloc]initWithFrame:self.view.bounds];
_tableView.dataSource =self;
_tableView.delegate =self;
_tableView.rowHeight =60;
[self.viewaddSubview:_tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];
HerosModel *model = self.dataArray[indexPath.row];
cell.imageView.image = [UIImageimageNamed:model.icon];
cell.textLabel.text = model.name;
cell.detailTextLabel.text = model.intro;
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark -
#pragma mark - 要不要显示出复制/粘贴菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
// 第一行长按cell后不会出现菜单
if (indexPath.row ==0) {
return NO;
} else {
return YES;
}
}
#pragma mark -
#pragma mark - 决定菜单上显示的名称
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullableid)sender {
// 菜单中只有 copy 和 past会显示出来
if (action == @selector(copy:) || action == @selector(paste:)) {
return YES;
} else {
return NO;
}
}
/**
@property(nullable,nonatomic,copy) NSString *string;
@property(nullable,nonatomic,copy) NSArray<NSString *> *strings;
*/
#pragma mark -
#pragma mark - 点击菜单中选项会调用的方法
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullableid)sender {
if (action == @selector(copy:)) {
// copy 的数据是 被点击这一行的内容
// 1. 取出被点击cell对应的Model
HerosModel *heroModel = self.dataArray[indexPath.row];
// 2. 把内容保存到剪贴板上 ,剪贴板是属于全局的
[UIPasteboard generalPasteboard].strings = @[heroModel.icon,heroModel.name,heroModel.intro];
} else if (action ==@selector(paste:)) {
// 1. 取出剪贴板中保存的内容
NSArray *contentArray = [UIPasteboardgeneralPasteboard].strings;
// 2. 实例化一个heroModel 对象
HerosModel *heroModel = [[HerosModelalloc]init];
heroModel.icon = contentArray[0];
heroModel.name = contentArray[1];
heroModel.intro = contentArray[2];
// 3. 刷新数据源,插入的数据会放到被点击的cell的上一行
[_dataArray insertObject:heroModel atIndex:indexPath.row];
[_tableViewinsertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];
}
}
- tableView中的cell复制粘贴操作
- tableView中cell的删除、插入、移动、复制粘贴问题详解代码分析
- 获取tableview中的cell
- cygwin粘贴复制操作
- cygwin粘贴复制操作
- vim 复制 粘贴 操作
- VIM复制粘贴操作
- vi中的复制,粘贴
- Android中的复制粘贴
- Android中的复制粘贴
- Android中的复制粘贴?
- Android中的复制粘贴
- Android中的复制粘贴
- Android中的复制粘贴
- TableView中的cell不可点击
- Windows下cmd(命令提示符)中的复制粘贴操作
- javascript 复制与粘贴操作
- Ubuntu的复制粘贴操作
- 2016年5月1日
- 远程连接mysql/mariaDB数据库时出现1045错误
- 204. Count Primes
- 关于居中
- CM和CMTS的概念和信令交互过程
- tableView中的cell复制粘贴操作
- bzoj 2588: Spoj 10628. Count on a tree(树上主席树)
- IOS总体学习思路(16.5.1)
- 是时候贴上校园漫游的成品了【记录】
- 如何复制cmd命令行文字
- ActiveMQ小记(一):监控
- AndroidStudio中使用Git-初级篇(一)——从github上传和下载项目(by 星空武哥)
- Hadoop2.*源码分析之Job任务提交与执行
- Linux基本命令01