I am in the process of adding all of my data to my iPhone application, the coding is done other than hard coding the data into it. I have run into an issue. I am using UITableviews and I am adding around 150-250 items per table view, it allows me to add the data, but when I run it won't let me scroll down past about 12 items. I would like to be able to scroll through all 200+ of my items, but as I said it only allows the first 12 or so. I will post a snippet of my code below.
RootTableViewController.h
#import <UIKit/UIKit.h>
@interface RootTableViewController : UITableViewController
@end
RootTableViewController.m
#import "RootTableViewController.h"
#import "SecondTableViewController.h"
@interface RootTableViewController ()
@end
@implementation RootTableViewController
{
NSArray *states;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
states = [NSArray arrayWithObjects:@"Alabama", @"Georgia", @"Tennessee", @"Colorado", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [states count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//table identifier
static NSString *simpleTableIdentifier = @"StateCell";
//creating a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
//if cell doesn't have anything in it, creates a new one
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
//creates text for cell, depending on what row it is
cell.textLabel.text = [states objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Chalkduster" size:17];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//push segue identifier 'showArrayDetail'
if([segue.identifier isEqualToString:@"showStateDetail"])
{
//row that we clicked on
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//'SecondTableVieController' object is created
SecondTableViewController *destViewController = segue.destinationViewController;
//sets 'stateName' to what row you pick
destViewController.stateName = [states objectAtIndex:indexPath.row];
//sets title to 'stateName' you picked
destViewController.title = [NSString stringWithFormat:@"%@ Areas", destViewController.stateName];
}
}
@end
SecondTableViewController.h
#import <UIKit/UIKit.h>
@interface SecondTableViewController : UITableViewController
@property (nonatomic, strong) NSString *stateName;
@end
SecondTableViewController.m
#import "SecondTableViewController.h"
#import "ThirdTableViewController.h"
@interface SecondTableViewController ()
@end
@implementation SecondTableViewController
{
NSArray *areas;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//populating arrays
NSDictionary *dict = @{@"Alabama":@[@"Moss Rock Preserve Boulder Fields", @"Alabama Area 2",
@"Alabama Area 3"], @"Georgia": @[@"Georgia Area 1", @"Georgia Area 2", @"Georgia Area 3"],
@"Tennessee":@[@"Tennessee Area 1", @"Tennessee Area 2", @"Tennessee Area 3"],
@"Colorado":@[@"Colorado Area 1", @"Colorado Area 2", @"Colorado Area 3"]};
areas = dict[self.stateName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return areas.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"AreaCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.textLabel.text = areas[indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//push segue identifier 'showArrayDetail'
if([segue.identifier isEqualToString:@"showAreaDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ThirdTableViewController *destViewController = segue.destinationViewController;
destViewController.areaName = areas[indexPath.row];
destViewController.title = [NSString stringWithFormat:@"%@ Climbs", destViewController.areaName];
}
}
@end
ThirdTableViewController.h
#import <UIKit/UIKit.h>
@interface ThirdTableViewController : UITableViewController
@property (nonatomic, strong) NSString *areaName;
@end
ThirdTableViewController.m
#import "ThirdTableViewController.h"
#import "FourthTableViewController.h"
@interface ThirdTableViewController ()
@end
@implementation ThirdTableViewController
{
NSArray *climbs;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//populating arrays
NSDictionary *dict = @{@"Moss Rock Preserve Boulder Fields":@[@"Tesseract", @"Chalky Dreams",
@"Aristocratic Nose", @"Bee Stings", @"Recovery Run Traverse", @"Heel Shock", @"Fourth of July",
@"No Sack", @"Poop Dreams", @"Hoop Dreams", @"Grass Man Traverse", @"Mikey Likes It", @"Just
Throw", @"Rapture"], @"Georgia Area 1": @[@"Georgia Climb 1", @"Georgia Climb 2", @"Georgia
Climb 3"], @"Tennessee Area 1":@[@"Tennessee Climb 1", @"Tennessee Climb 2", @"Tennessee Climb
3"], @"Colorado Area 1":@[@"Colorado Climb 1", @"Colorado Climb 2", @"Colorado Climb 3"]};
climbs = dict[self.areaName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return climbs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"ClimbCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.textLabel.text = climbs[indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//push segue identifier 'showArrayDetail'
if([segue.identifier isEqualToString:@"showClimbDetail"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
FourthTableViewController *destViewController = segue.destinationViewController;
destViewController.climbName = climbs[indexPath.row];
destViewController.title = [NSString stringWithFormat:@"%@ Specs", destViewController.climbName];
}
}
@end
FourthViewController.h
#import <UIKit/UIKit.h>
@interface FourthTableViewController : UITableViewController
@property (nonatomic, strong) NSString *climbName;
@end
FourthViewController.m
#import "FourthTableViewController.h"
@interface FourthTableViewController ()
@end
@implementation FourthTableViewController
{
NSArray *specs;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//populating arrays
NSDictionary *dict = @{@"Tesseract":@[@"Alabama Spec 1", @"Alabama Spec 2", @"Alabama Spec 3"],
@"Georgia Climb 1": @[@"Georgia Spec 1", @"Georgia Spec 2", @"Georgia Spec 3"], @"Tennessee
Climb 1":@[@"Tennessee Spec 1", @"Tennessee Spec 2", @"Tennessee Spec 3"], @"Colorado Climb
1":@[@"Colorado Spec 1", @"Colorado Spec 2", @"Colorado Spec 3"]};
specs = dict[self.climbName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return specs.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SpecCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.textLabel.text = specs[indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Chalkduster" size:17];
return cell;
}
I was thinking I needed to add a "scrollable section" like I would in a Java application, but it is already scrollable....
Thanks