Frage

Ich versuche, den Typ der in der Pasteboard gefundenen Daten zu lesen.Das Programm kehrt jedoch zurück, dass ich ein Bild habe (wahrscheinlich, weil das der erste Zustand in der IF-Statement ist).Was mache ich falsch?Dies ist der Teil des Codes, auf den ich mich beziehe.Danke. generasacodicetagpre.

War es hilfreich?

Lösung

If you are just trying to read the type of the data from the pasteboard, you probably want to use either -canReadItemWithDataConformingToTypes: or -canReadObjectForClasses:options: in order to just test if these are available.

If you want to read the objects themselves, you're making the right calls, although the way that you are using them might retrieve more than one representation of the same item on the pasteboard in the event that there are multiple items on the pasteboard with both text and image representations.

You might also want to check for [pboardImg count] > 0. Although the documentation clearly states that nil will be returned if it can't create any objects of that type, you are unlikely to be able to do anything with a zero-length array anyway and the Objective-C dispatcher will short-circuit the call to nil returning 0 which will also fail the test (as you would want).

Andere Tipps

I have found a solution to this and as gaige said, the data returned contains not only the content that a user can see but many other kinds of information.

I have also found and experimented using other types of information available, some of which are the following:

*NSStringPboardType;        
*NSFilenamesPboardType;  
*NSTIFFPboardType;      
*NSRTFPboardType;      
...

However Xcode version that I am using states that some of these might be removed in future versions (am using xcode 3) so if anyone uses these be careful..

Thanks for the help!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top