2

This is within the latest Xcode.

I have 4 arrays that produce a result to the screen with an OK button. I would like to add a function that copies the result to the clipboard. Does that make sense?

While I am not exactly sure how this is done, I am heavily researching it as I am somewhat new to coding.

From what I am seeing, pasteboards would seem to be the way to go. Am I in the right ball field here?

Here is a sampling of my code:

-(IBAction)buttonPressed
{
NSInteger firstRow = [doublePicker selectedRowInComponent:kfirstComponent];
NSInteger middleRow = [doublePicker selectedRowInComponent:kmiddleComponent];
NSInteger lastRow = [doublePicker selectedRowInComponent:klastComponent];
NSInteger fourthRow = [doublePicker selectedRowInComponent:kfourthComponent];
NSString *first = [firstTypes objectAtIndex:firstRow];
NSString *middle = [middleTypes objectAtIndex:middleRow];
NSString *last = [lastTypes objectAtIndex:lastRow];
NSString *fourth = [fourthTypes objectAtIndex:fourthRow];
NSString *message = [[NSString alloc] initWithFormat:@"%@ %@ %@ %@.",first, middle, last, fourth]; 
UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Text"
    message:message
            delegate:nil
    cancelButtonTitle:@"OK"
    otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}

This is the code (I think) i want to Implement:

-(IBAction)copy:(id)sender
{
NSString *copyString = label.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyString];
}

And if I have the correct usage, I am not sure where to put it.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • You might want to clarify the platform (OS X?) and APIs you're trying to target. It's a completely different concept to manipulate the clipboard for every single major OS. – lunixbochs Feb 27 '12 at 23:08
  • And... You are correct. I wrongly assumed that this was strictly Xcode. Sorry about that. – Phineas T Parks Feb 28 '12 at 01:24

1 Answers1

0

Add:

UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:message];

below the line of code that delivers the result.


This answer was posted as an edit to the question Sending text results to the clipboard in Xcode (Found the solution) by the OP Phineas T Parks under CC BY-SA 3.0.

vvvvv
  • 25,404
  • 19
  • 49
  • 81