Silver Challenge


I am trying to create a way to print “No more items” and will need a variable to access throughout the ItemsViewController. I tried to create the variable “tr” as indicated below, but the program won’t recognize its value. This seems like it should be simple. Once I get the variable, I can use it towards the end in an if-else construct.

What am I doing wrong?


[code]#import <Foundation/Foundation.h>

@interface ItemsViewController : UITableViewController

int tr;

// I initially got warning stating this must be nonatomic,
// that’s why I declared it as such

@property (nonatomic, readonly) int tr;


#import "ItemsViewController.h"
#import "BNRItemStore.h"
#import "BNRItem.h"

@implementation ItemsViewController

// tr to represent number of total rows

@synthesize tr;

- (int)tr
    return 5;

- (id)init
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        for (int i = 0; i < tr; i++) {
            [[BNRItemStore sharedStore] createItem];
    return self;

- (id)initWithStyle:(UITableViewStyle)style
    return [self init];

- (NSInteger)tableView:(UITableView *)tableView
    [[[BNRItemStore sharedStore] allItems] count];


- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"UITableViewCel"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
    BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[p description]];
    return cell;



You should not be doing that just count the number of rows in the section.