iCulture forum | iPhone, iPad,  iPod touch, Apple TV en iOS

iCulture forum | iPhone, iPad, iPod touch, Apple TV en iOS (https://forum.iculture.nl/)
-   Ontwikkelen voor iOS (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/)
-   -   Selectie in UITextView voorkomen (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/41864-selectie-uitextview-voorkomen.html)

SkyTrix 17-08-09 13:44

Selectie in UITextView voorkomen
 
Hey

Ik heb een UITextView en kan al een property zetten dat de inhoud daarvan niet kan gewijzigd worden. Mensen kunnen dus gewoon de inhoud lezen. Nu kan men deze inhoud wel nog kopiëren door even op te tappen en dan select all te kiezen en dan kopiëren...

Is er een manier om te voorkomen dat de inhoud van een UITextView gekopieerd wordt?

Bedankt

Nikooos 17-08-09 14:57

ik vond wel een stukje code die het klembord leeggooid als je de app verlaat. Dus het nooit kan kopieren in een andere functie:

Code:

- (void)applicationWillTerminate:(UIApplication *)application {

  NSLog(@"application terminating");

  // Clear pasteboard to prevent pasting into other applications:
  UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  pasteBoard.items = nil;

}


SkyTrix 17-08-09 14:58

Das zeker al bruikbaar, bedankt. Zou nog beter zijn moest ik iets hebben die maakt dat je zelfs niet kan selecteren.. Ben zelf ook nog niks tegengekomen tot nu toe.

Nikooos 17-08-09 15:06

Ik ben even aan het zoek geweest voor je, maar voorlopig is dit het beste wat ik kon vinden.

Ik las wel iets over dat je met UIResponder iets kan doen, maar het is me nog niet duidelijk wat dat is om te voorkomen dat je kan kopieren.

SkyTrix 17-08-09 15:07

Bedankt, ik zoek nog even verder.

Nikooos 17-08-09 15:16

Code:

"The UIResponder class declares the method canPerformAction:withSender:. Responder classes can implement this method to show and remove commands of the editing menu based on the current context."

"The menu initially includes all commands for which the first responder has corresponding UIResponderStandardEditActions method implementations (copy:, paste:, and so on). Before the menu is displayed, however, the system sends a canPerformAction:withSender: message to the first responder, which in many cases is the custom view itself. In its implementation of this method, the responder evaluates whether the command (indicated by the selector in the first argument) is applicable in the current context. For example, if the selector is paste: and there is no data in the pasteboard of a type the view can handle, the responder should return NO to suppress the Paste command. If the first responder does not implement the canPerformAction:withSender: method, or does not handle the given command, the message travels up the responder chain.

Listing 3-5 shows an implementation of the canPerformAction:withSender: method that looks for message matching the copy:, copy:, and paste: selectors; it enables or disables the Copy, Cut, and Paste menu commands based on the current selection context and, for paste, the contents of the pasteboard."


- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    BOOL retValue = NO;
    ColorTile *theTile = [self colorTileForOrigin:currentSelection];
 
    if (action == @selector(paste:) )
        retValue = (theTile == nil) &&
            [[UIPasteboard generalPasteboard] containsPasteboardTypes:
            [NSArray arrayWithObject:ColorTileUTI]];
    else if ( action == @selector(cut:) || action == @selector(copy:) )
        retValue = (theTile != nil);
    else
        retValue = [super canPerformAction:action withSender:sender];
    return retValue;
}

From the ADC Reference Library Here (http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html#//apple_ref/doc/uid/TP40007072-CH9-SW34)

So basically, just return NO for the selectors cut: copy: and paste: in this method in the first responder or parent in the responder chain.

Hier nog een stukje dat de echte oplossing zou zijn, maar ik weet niet of dit ook voor textviews werkt of alleen voor textfields.

SkyTrix 17-08-09 15:23

Ik zou dus een custom UITextView moeten maken met die method en voor iedere selector NO returnen?

Nikooos 17-08-09 15:26

Dat is wat ik er zo ongeveer van begreep, maar heb het niet zelf geprobeerd.

SkyTrix 17-08-09 15:38

Heeft niet geholpen :/ UITextView gesubclassed met die method, zelfs voor elke action NO gereturned. Blijft gewoon kopiëren..

Nikooos 17-08-09 15:49

hmm.. dan heb ik helaas ook geen oplossing voor je..

SkyTrix 17-08-09 15:50

Jammer, maar super bedankt voor al je moeite!

Whacko 17-08-09 16:23

hij blijft kopieren omdat de copy events door de hele responder chain gaan. subviews van UITextView krijgen die events nog binnen. indien mogelijk zou je die ook moeten subclassen. "Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command."

SkyTrix 17-08-09 16:51

Citaat:

Oorspronkelijk geplaatst door Whacko (Bericht 339321)
hij blijft kopieren omdat de copy events door de hele responder chain gaan. subviews van UITextView krijgen die events nog binnen. indien mogelijk zou je die ook moeten subclassen. "Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command."

Mijn UITextView heeft heeft geen subviews.. Ik begrijpt het precies niet zo goed. Hoe kan een ander object nu YES returnen als er maar 1 instance is van mijn custom UITextView?

Whacko 17-08-09 17:30

een standaard UITextview heeft volgens mij al subviews: Timberline: /Users/ericasadun/Headers/merged/UIKit/UITextView.h Source File

als dan een van die objecten zegt dat zijn text gekopieerd kan worden, dan doet ie dat gewoon.

SkyTrix 17-08-09 17:33

Hoe kan ik daar dan rond..? :s

Whacko 17-08-09 18:29

ik weet het niet zeker, maar ik denk dat dit een mogelijke oplossing is:

iPhone Custom Class / Object in Responder Chain - Stack Overflow

een category maken op de views die canPerformAction implementeren, en dan daar uitschakelen ofzo.


Alle tijden zijn GMT +2. Het is nu 12:10.