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 Exploring the Master-Detail Template Passing Data To The Detail View

Yudan Chen
Yudan Chen
1,185 Points

Title did not appear on the DetailView after pressing the cell on MasterView, Why?

I have rechecked all the codes, and everything look the same. Is it possible because I am using xcode 6.4? Thank you for answering

Dee Greene
Dee Greene
8,508 Points

Can you add your code so we can see it?

1 Answer

Yudan Chen
Yudan Chen
1,185 Points
#import "MasterViewController.h"
#import "DetailViewController.h"
//"()" indicate defining private instance
@interface MasterViewController ()

@property NSMutableArray *objects;
@implementation MasterViewController

- (void)awakeFromNib {
    [super awakeFromNib];

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlesArray = [NSArray arrayWithObjects:@"1", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9",


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

#pragma mark - Segues
//sender is who generated the segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSString *title = self.titlesArray[indexPath.row];
        [[segue destinationViewController] setDetailItem:title];
        //destanationViewController is the detailedViewController

#pragma mark - Table View
//define number of section in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
//define number of row in each section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titlesArray.count;
//this method manage the table view
//cellForRowAtIndexPath return a cell for the table view
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    //reuse cell to rotate each line in the table view
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    //dose not reuse cell, it would alloc as many cell as the line that we have
    //UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseldentifier:@"Cell"];
//indexPath contain row and section
    NSString *object = self.titlesArray[indexPath.row];
    //[self.titlesArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [object description];
    return cell;

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;

Dee Greene
Dee Greene
8,508 Points

do you have the title set as an outlet in the detail view? you would need to

  • create an outlet for the text in the header file.
  • create an NSSTRING variable to store the title
  • change the outlet text to the NSSTRING variable in the viewDidLoad method of the detailView.m file
  • update the NSSTRING variable in your prepareForSegue method above