Copy functionality in iOS by using UIPasteboard

2019-03-10 13:26发布

 NSString *copyStringverse = [[NSString alloc] initWithFormat:@"%@",[textview.text]];
 UIPasteboard *pb = [UIPasteboard generalPasteboard];
 [pb setString:copyStringverse];

I am using above code for copying contents in textview,but I want to copy contents in a cell of the table. How to do this. Thanks in advance.

5条回答
萌系小妹纸
2楼-- · 2019-03-10 13:50

For Swift2.2

UIPasteboard.generalPasteboard().string = tableViewCell.textLabel.text

By using this you can directly set the value to UIPasteboard.

查看更多
再贱就再见
3楼-- · 2019-03-10 13:59

For Swift 2.1+:

let cell = tableView.cellForRowAtIndexPath(indexPath) as! UITableViewCell // change this to your custom cell if you use one
UIPasteboard.generalPasteboard().string = cell.textLabel.text
查看更多
Lonely孤独者°
4楼-- · 2019-03-10 14:01

For Swift 3.x

UIPasteboard.general.string = "String to copy"
查看更多
小情绪 Triste *
5楼-- · 2019-03-10 14:07

Well you don't say exactly how you have your table view cell set up, but if it's just text inside your table view it could be as easy as:

// provided you actually have your table view cell
NSString *copyStringverse = yourSelectedOrClickedTableViewCell.textLabel.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
查看更多
戒情不戒烟
6楼-- · 2019-03-10 14:11
[UIPasteboard generalPasteboard].string = @"Copy me!";
查看更多
登录 后发表回答