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

我正在使用上面的代码复制内容textview,但我想复制表格单元格中的内容。这该怎么做?

4

5 回答 5

72

好吧,您并没有确切说明您是如何设置表格视图单元格的,但如果它只是表格视图中的文本,则它可能很简单:

// provided you actually have your table view cell
NSString *copyStringverse = yourSelectedOrClickedTableViewCell.textLabel.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];
于 2012-01-15T12:25:23.480 回答
27
[UIPasteboard generalPasteboard].string = @"Copy me!";
于 2014-08-07T10:57:52.933 回答
15

对于 Swift 3.x

UIPasteboard.general.string = "String to copy"
于 2016-12-03T22:31:24.430 回答
4

对于 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
于 2016-02-01T10:30:28.797 回答
1

对于 Swift2.2

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

通过使用它,您可以直接将值设置为UIPasteboard

于 2016-10-14T12:34:15.887 回答