私はCTFramesetterCreateWithAttributedString
を使用する場合editor.Iが問題に会ったOmniGroupのRTF形式に基づいて画像のサポートを追加するプロジェクトに焦点を当て、それがあるメモリ管理CTRunDelegateRef iPhone
EXC_BAD_ACCESS
を受けるためゾンビオブジェクトに起因します。
簡単にするために、私はNSAttributedString
を写真のみのrtfdファイルから入手します。オムニのサンプルに基づいて、iOS上に画像タグを解析するメソッドを追加します。そしてNSAttributedString
を作成するための部分が、このtutorial from raywenderlichが続く、とのように見えるされています。ここappendString:attributes:
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateCurrentVersion;
callbacks.getAscent = ascentCallback;
callbacks.getDescent = descentCallback;
callbacks.getWidth = widthCallback;
callbacks.dealloc = deallocCallback;
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, imgAttr);
NSDictionary *imgAttr = [NSDictionary dictionaryWithObjectsAndKeys:imgWidth,kImageWidth,imgHeight,kImageHeight, nil];//recored the width and height
NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:(id)delegate, (NSString*)kCTRunDelegateAttributeName,nil];
[_attributedString appendString:@" " attributes:attrDictionaryDelegate];
CFRelease(delegate);
オムニによって提供されており、NSMutableAttributedString
のカテゴリである:私はテストParserクラスで
- (void)appendString:(NSString *)string attributes:(NSDictionary *)attributes;
{
NSAttributedString *append;
append = [[NSAttributedString alloc] initWithString:string attributes:attributes];
[self appendAttributedString:append];
[append release];
}
CTFramesetterCreateWithAttributedString
と正常に作成され、メモリの問題は発生しません。しかし、ビュークラスでCTFramesetterCreateWithAttributedString
と呼ぶと、EXC_BAD_ACESS
という問題が発生します。私はここeditFrameがOmniFrameworkによって提供さOUIEditableFrame
のIVARあるviewDidLoad:
NSArray *arr = [OUIRTFReader parseRTFString2:rtfString];
self.editFrame.attributedText = [arr objectAtIndex:0];
//for OUIRTFReader
+ (NSArray *)parseRTFString2:(NSString *)rtfString
{
OUIRTFReader *parser = [[self alloc] _initWithRTFString:rtfString];
NSMutableArray *temp = [NSMutableArray arrayWithCapacity:1];
NSAttributedString *tempAstr = [[NSAttributedString alloc] initWithAttributedString:parser.attributedString];
[temp addObject:tempAstr];
[tempAstr release];
if (parser.zjImageArray) {
[temp addObject:parser.zjImageArray];
}
[parser release];
}
に私の見解にCTFramesetterCreateWithAttributedString
を送ります。 その後、layoutSubview:
のOUIEditableFrame
には、CTFramesetterCreateWithAttributedString
が失敗しました。これは
に割り当て解除オブジェクト(ゾンビ)に送信されたことを実証Objective-Cのメッセージがアドレス
NSDictionary *imgAttr = [NSDictionary dictionaryWithObjectsAndKeys:imgWidth,kImageWidth,imgHeight,kImageHeight, nil];
:器具とプロファイリング、それにゾンビオブジェクトがある点
私はUIKitやその他のようなコアファンデーションに精通していません。だから、私のコードでCTRunDelegateRefを使ってイメージの属性付き文字列を作成する方法に何が問題なのかを知りたいのですが?
ありがとうございます!
しかし、私はNSDictionaryクラスメソッドを使用し、deallocCallbackは何もしませんでした。 – scorpiozj
私はallocを使用してdeallocCallbackを実装していますが、問題はありません。それは私を混乱させます。とにかく、あなたは正しいです! – scorpiozj