Search code examples
iosobjective-ccocoa-touchnslog

Titles and NSLog not running in cellForRowAtIndexPath


I can't seem to understand why I can't display the title and subtitle for my cell. I've tried getting the string objects through NSLog(), but I don't receive any output aside from the NSLog() that successfully prints the memory location of the test object ( a Stack object) in the array, array_Stacks.

here is my cellForRowAtIndexPath: method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleCell" forIndexPath:indexPath];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleCell"];
    }

    NSString *cell_Title = [[array_Stacks objectAtIndex:[indexPath row]] title];
    NSString *cell_Subtitle = [[array_Stacks objectAtIndex:[indexPath row]] subject];

    NSLog(@"%@", cell_Title);

    NSLog(@"%@", [array_Stacks objectAtIndex:[indexPath row]]);
    NSLog(@"%@", cell_Subtitle);

    cell.textLabel.text = cell_Title;
    cell.textLabel.tintColor = [cp color_master_tan];
    cell.detailTextLabel.text = cell_Subtitle;
    cell.detailTextLabel.tintColor = [cp color_master_tan];
    //cell.imageView.image = [UIImage imageNamed:@"asset_Cell"];

    return cell;
}

Note: "cp" is my color palette object and is returning a UIColor object.

Here is Stack.m

#import "Stack.h"
#import "FlashCard.h"

/*
 Notes

 * Need to get the name of the creator and add it to the default init.

 */

@implementation Stack
{
    NSMutableArray *array_flashCard;
}
@synthesize title, subject, creator, array_FlashCard;

#pragma mark - Initializers

- (id)init {
    return [self initWithTitle:@"New Stack" subject:@"No Subject" creator:@"None Listed" array:array_FlashCard];
}

- (id)initWithTitle:(NSString *) ttl subject:(NSString *) sbj creator:(NSString *) ctr array:(NSMutableArray *) arr {
    self = [super init];
    if (self) {
        title = ttl;
        subject = sbj;
        creator = ctr;
        array_FlashCard = arr;

        title = [[NSString alloc] init];
        subject = [[NSString alloc] init];
        creator = [[NSString alloc] init];
        array_FlashCard = [[NSMutableArray alloc] init];

    }
    return self;
}

#pragma mark - Array Operations

- (void)addFlashCardToArray:(FlashCard *) flashcard { [array_FlashCard addObject:flashcard]; }

@end

Solution

  • You are setting your strings to @"" in your Stack initWithTitle:....

        title = ttl;
        subject = sbj;
        creator = ctr;
        array_FlashCard = arr;
    
        title = [[NSString alloc] init]; // Throw away previous value; assign new empty string.
        subject = [[NSString alloc] init]; // Throw away previous value; assign new empty string.
        creator = [[NSString alloc] init]; // Throw away previous value; assign new empty string.
        array_FlashCard = [[NSMutableArray alloc] init]; // Throw away previous value; assign new empty array.