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 Blog Reader iPhone App Getting Data from the Web What is NSDictionary?

Shaun Kelly
Shaun Kelly
5,648 Points

No Titles?

- (void)viewDidLoad {
    [super viewDidLoad];



    NSDictionary *blogPost1 = [NSDictionary dictionaryWithObjectsAndKeys:@"The Missing Widget in Android",@"Title",@"Shaun Kelly",@"Author",@"2005",@"Release Date", nil];


    NSDictionary *blogPost2 = [NSDictionary dictionaryWithObjectsAndKeys:@"Getting started with ios development",@"Title",@"Shaun Kelly",@"Author",@"2015",@"Release Date", nil];

    NSDictionary *blogPost3 = [NSDictionary dictionaryWithObjectsAndKeys:@"How to Make an app game",@"Title",@"Shaun Kelly",@"Author",@"Release Date",@"2015",@"Cost",@"2.99", nil];

    self.blogPosts = [NSArray arrayWithObjects:blogPost1,blogPost2,blogPost3, nil];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.

    return [self.blogPosts count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //creating a cell object that can be reused
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    //NSDictionary object and setting the value to the blogPosts array at the index of the cell row
    NSDictionary *blogPost = [self.blogPosts objectAtIndex:indexPath.row];

    //setting the text of the cell and retrieving the titles from the NSDictionary
    cell.textLabel.text = [blogPost valueForKey:@"title"];

    // Configure the cell...

    return cell;
}

//setting the text of the cell and retrieving the titles from the NSDictionary cell.textLabel.text = [blogPost valueForKey:@"title"]----->you used dictonary capital" T"itle thas should be T

2 Answers

Tingting Gu
Tingting Gu
10,760 Points

Your key is "Title" in dictionary, but valueForKey is "title". You should use the same uppercase key as follows:

cell.textLabel.text = [blogPost valueForKey:@"Title"];