macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

textView:writablePasteboardTypesForCell:atIndex:

テキストビューからアタッチメントセルをペーストボードに書き込もうとしたとき(カット、コピー、ドラッグなど)に呼び出されます
-(NSArray *)textView:(NSTextView *)view:
               writablePasteboardTypesForCell:(id <NSTextAttachmentCell>)cell:
               atIndex:(unsigned)charIndex:

解説

テキストビューからアタッチメントセルをペーストボードに書き込もうとしたとき(カット、コピー、ドラッグなど)に呼び出されます。

返り値

( NSArray * )

配列

引数

( NSTextView * )view

テキストビュー

( id <NSTextAttachmentCell> )cell

セル

( unsigned )charIndex

先頭からの番号(文字数)

フレームワーク

ApplicationKit

クラス

NSTextView

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"
//TextViewからこのクラスにdelegateしている
@implementation MyObject
- (NSArray *)textView:(NSTextView *)aTextView writablePasteboardTypesForCell:(id <NSTextAttachmentCell>)attachmentCell atIndex:(unsigned)charIndex
{
NSLog([NSString stringWithFormat:@"charIndex = %d",charIndex]);
return nil;//Arrayを返さなければいけない
}

- (IBAction)myAction:(id)sender
{
NSRange ran;
//テキストアタッチメント
    NSTextAttachment *theAttachment;
    //ファイルラッパ
    NSFileWrapper *theWrapper = [[[NSFileWrapper alloc] initWithPath:
            [[NSBundle mainBundle] pathForResource:@"image" ofType:@"tiff"]] autorelease];
    //テキストアタッチメント
    theAttachment = [[[NSTextAttachment alloc] initWithFileWrapper:theWrapper] autorelease];
    //
    [[myOutlet textStorage] appendAttributedString:
            [NSAttributedString attributedStringWithAttachment:theAttachment]];
            
ran = NSMakeRange(1,3);
[myOutlet insertText:@"<-clich!"];

[myOutlet smartInsertBeforeStringForString:@"sss"
            replacingRange:ran];
}

@end