首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在循环中使用CTFontRef创建NSMutableAttributedString时遇到的问题

在循环中使用CTFontRef创建NSMutableAttributedString时遇到的问题
EN

Stack Overflow用户
提问于 2011-06-14 15:09:16
回答 1查看 964关注 0票数 1

我需要为该字符串中的不同范围创建一个具有不同CTFontRef和CTParagraphStyleRef的CTParagraphStyleRef。

我尝试通过将以下代码放入循环并根据需要更改范围来创建它,

代码语言:javascript
复制
CTFontRef normalFontRef = CTFontCreateWithName((CFStringRef)@"CourierNewPSMT", fontsize, NULL);
NSDictionary* normalFontAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)normalFontRef,(NSString*)kCTFontAttributeName, nil];
[attributedString addAttributes:normalFontAttribute range:range];

CFRelease(normalFontRef);
[normalFontAttribute release];
normalFontAttribute = nil;

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
NSDictionary* paragraphAttribute = [[NSDictionary alloc] initWithObjectsAndKeys:(id)paragraphStyle,(NSString*)kCTParagraphStyleAttributeName, nil];
[attributedString addAttributes:paragraphAttribute range:range];

CFRelease(paragraphStyle);
paragraphAttribute release];
paragraphAttribute = nil;

我的问题是:

该应用程序崩溃后,在设备的一些循环迭代,没有显示任何细节。只要关闭应用程序,没有崩溃报告,没有消息在控制台,没有gdb断点。

更多解释:--我在另一个循环中调用这个NSMutableAttributedString创建方法,用于其他一些处理,该循环是崩溃的循环,而不是NSMutableAttributedString创建循环。但是,如果我注释了调用上述方法并使用create a NSMutableAttributedString,它可以正常工作,请参见下面的

代码语言:javascript
复制
//works fine
attributtedString = [[NSMutableAttributedString alloc] initWithString:stringContent];

//not working 
attributtedString   = [self createattributtedString:stringContent];
//this createattributtedString: method contain the first listed code 

提前谢谢,

EN

回答 1

Stack Overflow用户

发布于 2011-06-27 13:58:17

你可能有个没完没了的循环。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6345780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档