Copy functionality in iOS by using UIPasteboard

前端 未结 5 728
清歌不尽
清歌不尽 2021-02-02 06:04
 NSString *copyStringverse = [[NSString alloc] initWithFormat:@"%@",[textview.text]];
 UIPasteboard *pb = [UIPasteboard generalPasteboard];
 [pb setString:copy         


        
相关标签:
5条回答
  • 2021-02-02 06:23

    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];
    
    0 讨论(0)
  • 2021-02-02 06:32
    [UIPasteboard generalPasteboard].string = @"Copy me!";
    
    0 讨论(0)
  • 2021-02-02 06:32

    For Swift 3.x

    UIPasteboard.general.string = "String to copy"
    
    0 讨论(0)
  • 2021-02-02 06:36

    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
    
    0 讨论(0)
  • 2021-02-02 06:40

    For Swift2.2

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

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

    0 讨论(0)
提交回复
热议问题