使用 UIPasteboard 在 iOS 中复制功能

发布于 2024-12-27 11:21:09 字数 268 浏览 6 评论 0原文

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

I'm using above code for copying contents in textview, but I want to copy contents in a cell of the table. How to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鸠书 2025-01-03 11:21:09

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

// provided you actually have your table view cell
NSString *copyStringverse = yourSelectedOrClickedTableViewCell.textLabel.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyStringverse];

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];
坐在坟头思考人生 2025-01-03 11:21:09
[UIPasteboard generalPasteboard].string = @"Copy me!";
[UIPasteboard generalPasteboard].string = @"Copy me!";
赠意 2025-01-03 11:21:09

对于斯威夫特 3.x

UIPasteboard.general.string = "String to copy"

For Swift 3.x

UIPasteboard.general.string = "String to copy"
暗恋未遂 2025-01-03 11:21:09

对于 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

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
秋凉 2025-01-03 11:21:09

对于 Swift2.2

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

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

For Swift2.2

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文