BNRItemStore unknown receiver problem


#1

For some reason, my ItemsViewController doesn’t recognize BNRItemStore method. I’ve doubled checked the code and I’m pretty sure everything is correct. Can someone help?
BNRItemStore.h

[code] #import <Foundation/Foundation.h>
@class BNRItem;

@interface BNRItemStore : NSObject
{
NSMutableArray *allItems;
}

  • (BNRItemStore *)sharedStore;
  • (NSArray *)allItems;
  • (BNRItem *)createItem;
    @end
    [/code]

BNRItemStore.m

[code]#import “BNRItemStore.h”
#import “BNRItem.h”

@implementation BNRItemStore

  • (id)init
    {
    self = [super init];
    if (self) {
    allItems = [[NSMutableArray alloc] init];
    }
    return self;
    }

  • (NSArray *)allItems
    {
    return allItems;
    }

  • (BNRItem *)createItem
    {
    BNRItem *p = [BNRItem randomItem];
    [allItems addObject:p];
    return p;
    }

  • (BNRItemStore *)sharedStore
    {
    static BNRItemStore *sharedStore = nil;
    if (!sharedStore)
    sharedStore = [[super allocWithZone:nil] init];

    return sharedStore;
    }

  • (id)allocWithZone:(NSZone *)zone
    {
    return [self sharedStore];
    }

@end[/code]

ItemsViewController.m

[code]#import “ItemsViewController.h”
#import “BNRItemStore.h”
#import “BNRItem.h”

@implementation ItemsViewController

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

  • (id)initWithStyle:(UITableViewStyle)style
    {
    return [self init];
    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return [[[BNRItemStore sharedStore] allitems] count];
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“UITableViewCell”];

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

    BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[p description]];
    return cell;
    }

@end[/code]


#2

Finally broke and re-did everything instead of waiting for it to be handed to me on a silver platter lol. Anyway, no problems, but still not sure why it what the problem was. I guess we will never know!


#3

I’m guessing because of this piece of code

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[[BNRItemStore sharedStore] allitems] count]; }

You have “allitems” instead of allItems.