Copy functionality in iOS by using UIPasteboard

风格不统一 提交于 2019-12-03 06:28:33

问题


 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.


回答1:


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];



回答2:


[UIPasteboard generalPasteboard].string = @"Copy me!";



回答3:


For Swift 3.x

UIPasteboard.general.string = "String to copy"



回答4:


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



回答5:


For Swift2.2

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

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



来源:https://stackoverflow.com/questions/8869569/copy-functionality-in-ios-by-using-uipasteboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!