Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-21-2009, 06:28 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 33
Default Copy Text to Clipboard from TextView via Button?

Is there any way to copy text from a TextView that has User Interaction disabled to the clipboard via a UIButton?
kaje is offline   Reply With Quote
Old 07-22-2009, 12:04 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 95
Default

Quote:
Originally Posted by kaje View Post
Is there any way to copy text from a TextView that has User Interaction disabled to the clipboard via a UIButton?
What's the problem in just doing this in your IBOutlet for action?

Code:
	if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.utf8-plain-text"]])
		NSLog(@"WE gots a string which is: %@", pasteboard.string);
varchar is offline   Reply With Quote
Old 07-22-2009, 10:15 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 33
Default

Quote:
Originally Posted by varchar View Post
What's the problem in just doing this in your IBOutlet for action?

Code:
	if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.utf8-plain-text"]])
		NSLog(@"WE gots a string which is: %@", pasteboard.string);
That looks to be what I need but I'm having some issues with getting a value into the pasteboard.

Code:
- (IBAction)btnCopyClicked:(id)sender { 
	
	pasteboard.string = @"Test";
	if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:@"public.utf8-plain-text"]]) {
		NSLog(@"WE gots a string which is: %@", pasteboard.string);
	}
}
doesn't do anything and:

Code:
- (IBAction)btnCopyClicked:(id)sender { 
	
	pasteboard.string = @"Test";
	NSLog(@"Pasteboard: %@", pasteboard.string);
}
returns null.
kaje is offline   Reply With Quote
Old 07-22-2009, 11:22 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 95
Default

Code seems correct.

Make sure that you have the following in the property of interface

Code:
UIPasteboard *pastboard;
and the following in your init (or viewdidload) method

Code:
	pasteboard = [UIPasteboard generalPasteboard];
The above is important to initialize the pastboard.

Also, you must keep in mind that the pastboard will only get populated (based on what I know) ONLY from the copy, cut actions call out by the "OS". NOT by your function... So the process is:
  • user selects text
  • OS shows the call out (cut, copy)
  • user does a copy/cut
  • OS puts the text into the pasteboard stack (i.e. UIPastboard generalPastboard)
  • Then you can grab it from the general pastboard via pastboard.string
varchar is offline   Reply With Quote
Old 07-22-2009, 11:31 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 33
Default

Quote:
Originally Posted by varchar View Post
Code seems correct.

Make sure that you have the following in the property of interface

Code:
	pasteboard = [UIPasteboard generalPasteboard];
The above is important to initialize the pastboard.
That did the trick. In the early stages of troubleshooting the pasteboard, I took that out and forgot to put it back in. Doh! Thanks a lot!
kaje is offline   Reply With Quote
Old 10-06-2009, 06:46 AM   #6 (permalink)
Cramzy.com-Fun for iPhone
 
Join Date: Jan 2009
Posts: 111
Default

Hi!

Is there any way to use the UIPasteboard class and check for the device version so it works only in 3.0 and above?
I already did the check and stuff, the problem is that it won't compile for 2.2.1.

Any ideas what to do?

Cheers,
ILIYA
__________________
cramzy.com
loobian is offline   Reply With Quote
Reply

Bookmarks

Tags
copy, uibutton, uitextview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:34 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0