2012-07-30 19 views
1

我使用核心文本來顯示一些來自Web的json文本。 內容從被彈出的nsdictionary拉到UITABLEVIEW。ctframe不更新ctlines

我的問題是,ctframe不想更新最新的內容,它不斷重繪舊文本。我調試它,我很確定ctframesettercreateframe正在使用最新的NSAttributeString

這裏是我的代碼, 我在每一點調用此函數來顯示一個新的文本。該標記解析器會返回一個NSAtributeString

- (void)assign_text:(NSString*)text{ 
self.text = text; 


CGMutablePathRef path = CGPathCreateMutable(); //1 
CGPathAddRect(path, NULL, self.bounds); 

MarkupParser *markup = [[MarkupParser alloc]init]; 
NSAttributedString* attString = [markup attrStringFromMarkup: self.text]; 


CFAttributedStringRef a = (__bridge_retained CFAttributedStringRef)attString; 
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(a); //3 

ctFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL); 


CFRelease(a); 
CFRelease(path); 
CFRelease(framesetter); 


} 

- (void)drawRect:(CGRect)rect 
{ 

CGContextRef context = UIGraphicsGetCurrentContext(); 

// Flip the coordinate system 
CGContextSetTextMatrix(context, CGAffineTransformIdentity); 
CGContextTranslateCTM(context, 0, self.bounds.size.height); 
CGContextScaleCTM(context, 1.0, -1.0); 
CTFrameDraw((CTFrameRef)ctFrame, context); 

} 

回答