【发布时间】:2011-06-14 15:09:16
【问题描述】:
我需要为该字符串中的不同范围创建一个具有不同 CTFontRef 和 CTParagraphStyleRef 的 NSMutableAttributedString。
我尝试通过将以下代码放入循环中并根据需要更改范围来创建它,
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 创建循环。但是,如果我评论调用上述方法并使用创建 NSMutableAttributedString 它工作正常,见下文
//works fine
attributtedString = [[NSMutableAttributedString alloc] initWithString:stringContent];
//not working
attributtedString = [self createattributtedString:stringContent];
//this createattributtedString: method contain the first listed code
提前致谢,
【问题讨论】:
-
您是否在运行 iOS 3.1.xx 的设备上运行此功能 - 此功能仅适用于 3.2 及更高版本?
-
@deanWombourne,我在 iOS4.2.2 和 4.3.1 工作过
-
您查看了多少次 - 可能是内存问题?
-
您不应该返回属性字符串吗?很高兴在这里看到更多代码..
-
@Fossli 在那个 createattributtedString 函数中我将属性设置为参数字符串并最终返回。
标签: iphone ipad crash core-text