macOS/iOS API解説

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

目次

textView:clickedOnCell:inRect:atIndex:

テキストビューのアタッチメントセルをクリックしたときに呼び出されます
-(void)textView:(NSTextView *)textView:
               clickedOnCell:(id <NSTextAttachmentCell>)cell:
               inRect:(NSRect)cellFrame:
               atIndex:(unsigned)charIndex:

解説

テキストビューのアタッチメントセルをクリックしたときに呼び出されます。

返り値

( void )

なし

引数

( NSTextView * )textView

テキストビュー

( id <NSTextAttachmentCell> )cell

セル

( NSRect )cellFrame

セルのフレーム

( unsigned )charIndex

先頭からの位置(文字数)

フレームワーク

ApplicationKit

クラス

NSTextView

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"
//TextViewからこのクラスにdelegateしている
@implementation MyObject
- (void)textView:(NSTextView *)aTextView clickedOnCell:(id <NSTextAttachmentCell>)attachmentCell inRect:(NSRect)cellFrame atIndex:(unsigned)charIndex
{
NSLog([NSString stringWithFormat:@"cellFrame = %.1f,%.1f,%.1f,%.1f",cellFrame.origin.x,cellFrame.origin.y,cellFrame.size.width,cellFrame.size.height]);
NSLog([NSString stringWithFormat:@"charIndex = %d",charIndex]);
}

- (IBAction)myAction:(id)sender
{

//テキストアタッチメント
    NSTextAttachment *theAttachment;
    //ファイルラッパ
    NSFileWrapper *theWrapper = [[[NSFileWrapper alloc] initWithPath:
            [[NSBundle mainBundle] pathForResource:@"image" ofType:@"tiff"]] autorelease];
    //テキストアタッチメント
    theAttachment = [[[NSTextAttachment alloc] initWithFileWrapper:theWrapper] autorelease];
    //
    [myOutlet insertText:@"->"];
    [[myOutlet textStorage] appendAttributedString:
            [NSAttributedString attributedStringWithAttachment:theAttachment]];

[myOutlet insertText:@"<-clich!"];


}

@end