in course of developing app submitted bug report me - "cannot paste long text text field". sure enough, hangs "paste" bubble remaining blue tap , nothing ever happening. experimented little , found works 60,000 character file (and not take worryingly long time), 65537 kill every time.
i experimented further , found third party apps "notes" app show same behaviour.
if real problem in uitextview (in ios6) don't expect able fix huge text can pasted in avoid hang if possible. can suggest way of catching text before hangs uitextview?
edit: rmaddy, here's used make work:
#import <mobilecoreservices/utcoretypes.h> #define kuitextviewmaximumpaste (65000)
...
- (void)paste:(id)sender { uipasteboard *pb = [uipasteboard generalpasteboard]; nsstring *type = (nsstring *)kuttypetext; if ([pb containspasteboardtypes:@[type]]) { nsstring *txt = [pb valueforpasteboardtype:type]; if([txt length] > kuitextviewmaximumpaste) { [pb setvalue:[txt substringtoindex:kuitextviewmaximumpaste] forpasteboardtype:type]; } } [super paste:sender]; }
i had need similar different reasons. did implement paste:
method in custom view contained uitextview
. matt suggested in comment, may best create own custom subclass of uitextview
, implement paste:
method:
- (void)paste:(id)sender { if ([[uipasteboard generalpasteboard] containspasteboardtypes:[nsarray arraywithobjects:(nsstring *)kuttypeutf8plaintext, nil]]) { nsstring *txt = [[uipasteboard generalpasteboard] valueforpasteboardtype:(nsstring *)kuttypeutf8plaintext]; if (txt.length > 65535) { // oops - long // either truncate or ignore return; } } [super paste:sender]; }
you may need handle other pasteboard types. if user copies , paste part of webpage, may see other types being pasted.
Comments
Post a Comment