textView:clickedOnLink:atIndex:
テキストビューのリンクをクリックした時に呼び出されます
-(BOOL)textView:(NSTextView *)textView: clickedOnLink:(id)link: atIndex:(unsigned)charIndex:
解説
テキストビューのリンクをクリックした時に呼び出されます。
返り値
( BOOL )
YES/NO
引数
( NSTextView * )textView
テキストビュー
( id )link
リンク(URL)
( unsigned )charIndex
文字の番号
フレームワーク
ApplicationKit
クラス
NSTextView
Instance Methods
使用可能
10.0
参照
例文
#import "MyObject.h" //TextViewからこのクラスにdelegateしている @implementation MyObject -(BOOL)textView:(NSTextView *)textView clickedOnLink:(id)link atIndex:(unsigned)charIndex { //リンクをクリックしたら NSLog([NSString stringWithFormat:@"string No.%u,url %@",charIndex,[link description]]);//リンク先を表示 return YES; } - (IBAction)myAction:(id)sender { //htmlを読み込み NSURL *url = [NSURL URLWithString:@"http://www.oomori.com/"]; NSData *da = [url resourceDataUsingCache:YES]; NSDictionary *dic = [[[NSDictionary alloc] init] autorelease]; NSAttributedString *aString = [[[NSAttributedString alloc] initWithHTML:da documentAttributes:&dic] autorelease]; [[myOutlet textStorage] appendAttributedString:aString]; } @end