Copy Text to Clipboard from TextView via Button?

Discussion in 'iOS Programming' started by kwjohns, Jul 21, 2009.

  1. kwjohns macrumors 6502a

    kwjohns

    Joined:
    Jul 4, 2007
    #1
    Is there any way to copy text from a TextView that has User Interaction disabled to the clipboard via a UIButton?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. kwjohns thread starter macrumors 6502a

    kwjohns

    Joined:
    Jul 4, 2007
    #3
    Sorry, some of us are amateurs and aren't familiar with every framework and class or know what terms to search for such as "pasteboard." :rolleyes:
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    In neither method are you setting pasteboard to anything. Where do you set it to a valid instance of UIPasteboard? Are you sure it's set?

    Have you tried:
    Code:
    - (IBAction)btnCopyClicked:(id)sender { 
    	UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    	[pasteboard setValue: @"Test" forPasteboardType: @"public.utf8-plain-text"];
    	NSLog(@"Pasteboard: %@", pasteboard.string);
    }
    
     
  5. kwjohns thread starter macrumors 6502a

    kwjohns

    Joined:
    Jul 4, 2007
    #5
    I was missing the pasteboard = [UIPasteboard generalPasteboard]; which I had removed last night when troubleshooting it and forgot to add it back in. All is working now. Thanks.
     

Share This Page