2011-08-23 58 views
0

在下面的代碼中,當我點擊一個按鈕時,我推送一個新的UITableView。 TableView有25行。我可以看到第9排和第10排被切斷。我無法向下滾動查看其餘的行。我如何使TableView可滾動?謝謝。如何製作我的UITableView滾動?

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

以下是ListPicker

#import <Foundation/Foundation.h> 

@interface ListPicker : UITableViewController 
{} 
@end 

以下聲明爲ListPIcker

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

@implementation ListPicker 

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

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

-(void)dealloc{ 
    [super dealloc]; 
} 

-(void)viewDidLoad{ 
    [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]; 
} 


@end 
+2

不知道相關的問題,但在您的實現initWithStyle的':'你可能想要做'返回[超級initWithStyle:風格]'而不是'返回[自我的init];' – filipe

+0

做它彈跳嗎?或者表格是完全固定的? – TommyG

+0

@TommyG它的完全固定 – atbebtg

回答

1

嘗試添加:

yourTable.scrollEnabled = YES; 

此外,當您創建你的桌子公關ogrammatically,確保它是 「足夠長」,即

CGRect cgRct = CGRectMake(0, 0, 320, 600);   
yourTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStyleGrouped];  
+0

哪裏添加上面的代碼?從(IBAction)showListPicker:(id)發件人? – atbebtg

+0

通常在您的viewDidLoad中,但我沒有在這裏看到...也許你在視圖控制器中初始化一切。通常,我會建議你使用UIViewController而不是UITableViewController,並以編程方式添加所有這些。 – TommyG

+0

會做。那工作謝謝你! – atbebtg

0

而不是YES,寫真正,因爲它僅接受布爾值。

yourTable.scrollEnabled = true;