Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App UIKit Dynamics Extra Credit

App crash (unrecognized selector) for setting like button text

Using XCode6, downloaded the project from the download section of this unit.

Swapped app token and callback url.

And then run into a weird problem inside the THMetadataView:

If I do

[self.likesButton setTitle:@"2" forState:UIControlStateNormal];

the app runs fine and 2 actually shows up.

if I do

[self.likesButton setTitle:self.photo[@"likes"][@"count"] forState:UIControlStateNormal];

Then the app crashes after exiting setPhoto, it complains about "unrecognized selector"

In addition,

NSString *likeCount = self.photo[@"likes"][@"count"];
NSLog(@"%@ likes", likeCount);

It can totally be printed out normally. Just when it is added to the button title text, it causes the crashing

2 Answers

Figured it out!

The likeCount I got out of the NSDictionary is not a NSString, it is a NSNumber!

Andres Oliva
Andres Oliva
7,810 Points

Why are you accessing the instance variable? You should never do that! Use your property's getter!

I was just trying different stuff... yes, I did used the getter before, but it produced the same crashing result.