atbebtg atbebtg - 1 year ago 65
Objective-C Question

How do I make my UITableView Scroll?

In the following code, I push a new UITableView when I click on a button. The TableView has 25 rows. I can see the first 9 row and the 10th row got cut off. I can't scroll down to view the rest of the rows. How do I make the TableView scrollable? Thank you.

- (IBAction)showListPicker:(id)sender {
ListPicker *lp = [[ListPicker alloc] initWithStyle:UITableViewStyleGrouped];
[self setTitle:@"Home"];
[[self navigationController] pushViewController:lp animated:YES];
[lp release];

The following is the declaration for ListPicker

#import <Foundation/Foundation.h>

@interface ListPicker : UITableViewController

The following is the implementation for ListPIcker

#import "ListPicker.h"
#import "GameStore.h"
#import "List.h"
#import "HomeViewController.h"

@implementation ListPicker

- (id)init
return [super initWithStyle:UITableViewStyleGrouped];

return [self init];

[super dealloc];

[self setTitle:@"Select List"];
[[self navigationController] setNavigationBarHidden:NO];

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[[GameStore defaultStore] allLists] count];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if(cell == nil)
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"] autorelease];

NSArray *allList = [[GameStore defaultStore] allLists];
List *mylist = [allList objectAtIndex:[indexPath row]];
NSString *listTitle = [mylist label];

[[cell textLabel] setText:listTitle];
[cell setAccessoryType:UITableViewCellAccessoryNone];
return cell;

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
List *list = [[[GameStore defaultStore] allLists] objectAtIndex:[indexPath row]];
[[GameStore defaultStore] setSelectedList:list];

HomeViewController *hv = [[HomeViewController alloc] init];
[[self navigationController] popViewControllerAnimated:YES];


Answer Source

Try to add:

yourTable.scrollEnabled = YES;

Also, when you create your table programmatically, make sure it is "long enough", i.e.,

CGRect cgRct = CGRectMake(0, 0, 320, 600);          
yourTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStyleGrouped];    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download