Nicholas Gibson
Nicholas Gibson

Reputation: 316

Setting UILabel to Same value as NSString

I have searched for hours on this one subject and still have not been able to solve my problem. I have a string value that I need converted into a label. In my code I save the NSString and then make sure I am getting a value with the NSLog (which I DO). Then is where I am having problems. I try to set the label value equal to the nesting but when I run its NSLog I get (null). So my question is how may I make my label equal the value of my string? Thank you so much!

NSString *linkString = self.product[@"link"];

NSLog(@"%@", linkString);

linkLabel.text = linkString;

NSLog(@"%@", linkLabel);

Upvotes: 1

Views: 320

Answers (3)

bhr
bhr

Reputation: 2337

Did you forget to hook up the linkLabel in your XIB? Is the value of linkLabel not nil? What does NSLog(@"%@", linkLabel); print out?

Upvotes: 0

DeveloBär
DeveloBär

Reputation: 671

Are you sure that

NSString *linkString = self.product[@"link"];

works? Try this:

NSString *linkString = @"Test";

and use this for logging:

NSLog(@"%@", linkLabel.text);

Upvotes: 0

Eytan Schulman
Eytan Schulman

Reputation: 566

Your NSString will never be equal to your UILabel.

on the other hand, your UILabel's text property which is an NSString will be

try to change the code to this

NSString *linkString = self.product[@"link"];

NSLog(@"%@", linkString);

linkLabel.text = linkString;

NSLog(@"%@", linkLabel.text);

All I changed was linkLabel in your NSLog to linkLabel.text

Assuming like you said that linkString has a value, the second log should output the same as the first log.

EDIT: I saw your comment above, there is no need for a duplicate definition of the label as an @property and above that in the h file.

Upvotes: 2

Related Questions