NSPastedboardを用いる
ペーストボードを受け取る
汎用は以下で。
[NSPasteboard generalPasteboard];
ペーストボードは他に種類がある。以下で呼べる。
[NSPasteboard pasteboardWithName:name];
標準用は
NSGeneralPboard
NSFontPBoard
NSRulerBoard
NSFindPBoard
NSDragPboard
ペースボードをデータの種類に応じた初期化をする。
[board declareTypes:types owner:self];
typesはNSArrayに以下のグローバル変数の設定したい物を詰め込んでしていする。(標準用の場合)
APPKIT_EXTERN NSString *NSStringPboardType; // Use NSPasteboardTypeString 文字列
APPKIT_EXTERN NSString *NSFilenamesPboardType; // Use -writeObjects: to write file URLs to the pasteboard
APPKIT_EXTERN NSString *NSTIFFPboardType; // Use NSPasteboardTypeTIFF
APPKIT_EXTERN NSString *NSRTFPboardType; // Use NSPasteboardTypeRTF
APPKIT_EXTERN NSString *NSTabularTextPboardType; // Use NSPasteboardTypeTabularText
APPKIT_EXTERN NSString *NSFontPboardType; // Use NSPasteboardTypeFont
APPKIT_EXTERN NSString *NSRulerPboardType; // Use NSPasteboardTypeRuler
APPKIT_EXTERN NSString *NSColorPboardType; // Use NSPasteboardTypeColor
APPKIT_EXTERN NSString *NSRTFDPboardType; // Use NSPasteboardTypeRTFD
APPKIT_EXTERN NSString *NSHTMLPboardType; // Use NSPasteboardTypeHTML
APPKIT_EXTERN NSString *NSURLPboardType; // Use -writeObjects: to write URLs to the pasteboard
APPKIT_EXTERN NSString *NSPDFPboardType; // Use NSPasteboardTypePDF
APPKIT_EXTERN NSString *NSMultipleTextSelectionPboardType AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; // Use NSPasteboardTypeMultipleTextSelection
APPKIT_EXTERN NSString *NSPostScriptPboardType; // Use @"com.adobe.encapsulated-postscript"
APPKIT_EXTERN NSString *NSVCardPboardType AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; // Use (NSString *)kUTTypeVCard
APPKIT_EXTERN NSString *NSInkTextPboardType AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; // Use (NSString *)kUTTypeInkText
// HFS Promise type for dragging only
APPKIT_EXTERN NSString *NSFilesPromisePboardType AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; // Use (NSString *)kPasteboardTypeFileURLPromise
ペーストボードにデータを書き込む
NSDataを書き込みたい場合
[board setData:aData forType:dataType];
dataTypeには上記 NSStringPboardType等のそのデータのタイプを指定する。
[board setString:aString forType:dataType];
ペーストボードからデータを読み込む
[boad dataForType:dataType];
[boad stringForType:dataType];
dataTypeは NSStringPboardType等のそのデータのタイプを指定する
Viewにcut:,copy:,paste:を実装する。
-(IBAction)cut:(id)sender
-(IBAction)copy:(id)sender
-(IBAction)paste:(id)sender
最終更新:2011年12月08日 16:30