NSString *copyStringverse = [[NSString alloc] initWithFormat:@"%@",[textview.text]];
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
我正在使用上面的代码复制内容textview
,但我想复制表格单元格中的内容。这该怎么做?
NSString *copyStringverse = [[NSString alloc] initWithFormat:@"%@",[textview.text]];
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
我正在使用上面的代码复制内容textview
,但我想复制表格单元格中的内容。这该怎么做?
好吧,您并没有确切说明您是如何设置表格视图单元格的,但如果它只是表格视图中的文本,则它可能很简单:
// provided you actually have your table view cell
NSString *copyStringverse = yourSelectedOrClickedTableViewCell.textLabel.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
[UIPasteboard generalPasteboard].string = @"Copy me!";
对于 Swift 3.x
UIPasteboard.general.string = "String to copy"
对于 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
对于 Swift2.2
UIPasteboard.generalPasteboard().string = tableViewCell.textLabel.text
通过使用它,您可以直接将值设置为UIPasteboard
。