我正在将我的所有数据添加到我的iPhone应用程序中,编码完成的不是将数据硬编码到其中。我遇到了一个问题。我使用的是UITableviews,我在每个表格视图中添加了大约150-250个项目,它允许我添加数据,但是当我运行它时,不会让我向下滚动大约12个项目。我希望能够浏览所有200多个我的项目,但正如我所说,它只允许前12个左右。我将在下面发布我的代码片段。UITableview可滚动问题
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;
}
我想我需要添加一个 “滚动节” 就像我会在一个Java应用程序,但它已经是滚动....
谢谢
你用什么数组/字典填充tableView?如果在这种情况下使用'爬升',则只能获得大约3个项目。请提供您的代码为'tableView:cellForRowAtIndexPath'和'tableView:numberOfRowsInSection' – Emil
@Emil对不起,刚刚添加了我的代码的其余部分,应该更好地显示我的问题 – javaGeek
self.areaName的内容是什么? – J2theC