Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

killerham

macrumors newbie
Original poster
Sep 12, 2009
23
0
I'm trying to extract the string from NSAttributedString as an NSString like this:
Code:
// Extract the attributed label's(label) text 
NSString *text = [[NSString alloc] initWithString: [label string]];

But this doesn't work. There are no errors its just as if [label string] returns nothing. Any help on extracting the string from the attributed string will be appreciated.

Thanks
 
Its an instance of NSAttributedString which was taken from the OHAttributedLabel.
 
Its an instance of NSAttributedString which was taken from the OHAttributedLabel.

It should not matter where it was taken from. If it's a NSAttributedString (or subclass of the even) all the methods should work. What makes you believe that you are not getting the correct value when you use the label method? Have you displayed or printed the string? Are you sure label is not null? If you NSLog the length of label what is it?
 
The length of the returned string is 0. I know that there is a string from the OHAttributedLabel I'm getting it from but it isn't getting it properly.

*edit* Here is the block of code im using to get the NSAtrributedString from OHAttributedLabel
Code:
NSAttributedString* labelCopy = label.attributedText;
NSString *text = [[NSString alloc] initWithString: [labelCopy string]];
NSLog(@"%u",text.length);
 
The length of the returned string is 0. I know that there is a string from the OHAttributedLabel I'm getting it from but it isn't getting it properly.

When you say the returned string you mean:
Code:
NSLog("%d",[[label string] length])

or

Code:
NSLog("%d",[label length])

Also is label nil or not? As sending pretty much any message to a nil object will return 0
 
Sorry I'm an idiot. I was resetting the text before and it was obviously making the text nil. Thanks so much for your help!
 
Don't feel bad it happens to all of us. It brings to mind an old Chinese adage that translates to the effective, 'Sometimes even the monkey falls out of the tree.'
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.