Copy functionality in iOS by using UIPasteboard

stackiphone picture stackiphone · Jan 15, 2012 · Viewed 22.7k times · Source
 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?

Answer

Michael Dautermann picture Michael Dautermann · Jan 15, 2012

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