tek3
tek3

Reputation: 2115

CTLine Ref coming nil + CoreText + iPhone

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.

Upvotes: 0

Views: 447

Answers (2)

George Matiashvili
George Matiashvili

Reputation: 110

(CTLineRef)CFArrayGetValueAtIndex(lines,i);

use this instead of NSArray

line = (CTLineRef) [(NSArray *)lines objectAtIndex:i];

and make shore you not releasing lines before.

Upvotes: 0

Andrew
Andrew

Reputation: 2230

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

Upvotes: 1

Related Questions