UITableView only shows one item

#1

My UITableView only shows one item in a cell, I can not figure out what I am doing wrong.

AppDelegate.m
[

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    ItemViewController *items = [[ItemViewController alloc]init];
    self.window.rootViewController = items;
    return YES;
    }
    ]

ItemViewContoller.m
[
#import “ItemViewController.h”
#import “Items.h”
#import “ItemStore.h”

@interface ItemViewController ()

@end

@implementation ItemViewController

-(instancetype)init
{
self = [super initWithStyle:UITableViewStylePlain];
if(self)
{
for(int i=0;i<5;i++)
{
[[ItemStore sharedStore] createItems];
}
}
return self;
}
-(instancetype)initWithStyle:(UITableViewStyle)style
{
return [self init];
}
-(NSInteger)tableView:(UITableView )tableView numberOfRowsInSection:(NSInteger)section
{
return [[[ItemStore sharedStore] allItems] count];
}
-(UITableViewCell
)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@“UITableViewCell”];

NSArray *items = [[ItemStore sharedStore] allItems];
NSLog(@"%lu",[[ItemStore sharedStore].allItems count]);
Items *item = items[indexPath.row];
cell.textLabel.text = [item description];
return cell;

}
@end
ItemStore.h
]

[
#import <Foundation/Foundation.h>
@class Items;

@interface ItemStore : NSObject

@property (nonatomic,readonly,copy) NSArray *allItems;

+(instancetype)sharedStore;
-(instancetype)initWithPrivate;
-(Items*)createItems;
@end
]

ItemStore.m
[
#import “ItemStore.h”
#import “Items.h”
@interface ItemStore()

@property (nonatomic) NSMutableArray *privateItems;

@end

@implementation ItemStore
+(instancetype)sharedStore
{
static ItemStore *sharedStore;

if(!sharedStore)
{
    sharedStore = [[self alloc]initWithPrivate];
}
return sharedStore;

}
-(Items*)createItems
{
Items item = [Items randomItem];
[self.privateItems addObject:item];
//NSLog(@"%@",_privateItems);
return item;
}
-(NSArray
)allItems
{
return [self.privateItems copy];
}
-(instancetype)initWithPrivate
{
self = [super init];
if(self)
{
_privateItems = [[NSMutableArray alloc]init];
}
return self;
}
-(instancetype)init
{
[NSException raise:@“Singleton” format:@“Use +[ItemStore sharedStore]”];
return nil;
}
@end
]

Sorry, couldn’t figure out the right way to enter code into the forum.

#2

[quote]Sorry, couldn’t figure out the right way to enter code into the forum.
[/quote]
That’s as simple as using the Code tag to mark up your code.
Enter your code, select it, then press the Code button.

For example, here is your AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
   ItemViewController *items = [[ItemViewController alloc]init];
   self.window.rootViewController = items;
   return YES;
}

As for:

[quote]My UITableView only shows one item in a cell, I can not figure out what I am doing wrong.
[/quote]
If you post your code again, someone might be able to help.