CTLine 参考即将为零 +核心文本+ iPhone
我在 Core Text API 的 CTFrameGetLines(frameRef) 方法中遇到了一个奇怪的问题。我使用函数获取框架中存在的所有 CTLine 的数组
CFArrayRef lines = CTFrameGetLines( frameRef );
,然后计算 no。 在我的例子中, linesCount
linesCount = CFArrayGetCount (lines);
将变为 28。但是当我尝试使用lines数组中索引17处的行获取行时,
line = (CTLineRef) [(NSArray *)lines objectAtIndex:i];
我得到的行为零。我无法弄清楚linesCount的值何时变为28,那么lines数组中第17个索引处的值为什么为零。索引17处需要有一些行。
I am facing a strange problem with CTFrameGetLines( frameRef ) method of Core Text API. I am getting an array of all CTLines that are present in a frame using function
CFArrayRef lines = CTFrameGetLines( frameRef );
and then I am calculating no. of lines that are present using
linesCount = CFArrayGetCount (lines);
In my case linesCount is coming to be 28. But when I try get line at index 17 in lines array using
line = (CTLineRef) [(NSArray *)lines objectAtIndex:i];
I am getting line as nil. I am not able to figure out when value of linesCount is coming to be 28 , then how come the value at 17th index in lines array be nil.There's need to be some line present at index 17.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
objectAtIndex:永远不应该返回 nil,除非接收者为零。这意味着“行”为空。也许对 CTFrameGetLines 的调用失败。但这并不能解释为什么 CFArrayGetCount 会返回 28。每次都返回28吗? CFArrayGetValueAtIndex 返回什么?
安德鲁
objectAtIndex: should never return nil unless the receiver is nil. That would mean 'lines' is NULL. Maybe the call to CTFrameGetLines is failing. That doesn't explain why CFArrayGetCount would return 28 though. Does it return 28 every time? What does CFArrayGetValueAtIndex return?
Andrew
(CTLineRef)CFArrayGetValueAtIndex(行,i);
使用它代替 NSArray
line = (CTLineRef) [(NSArray *)lines objectAtIndex:i];
并让你之前不释放线。
(CTLineRef)CFArrayGetValueAtIndex(lines,i);
use this instead of NSArray
line = (CTLineRef) [(NSArray *)lines objectAtIndex:i];
and make shore you not releasing lines before.