2011-07-25 8 views
0

これはかなりシンプルですが、私はこれを明確に説明できることを願って - 私はコンテナに挿入するテーブルビューがありますトップ/ボトムに達するとテーブルが跳ね返ります。これまでのところ、私はテーブルをコンテナに置くことができましたが、コンテナ内のテーブルがバウンスしている間はコンテナはビュー上に固定されていました。再び、コンテナにテーブルを固定する方法を探していますが、コンテナはバウンスしています。ここでどのように私はビュー内でバウンスするuitableviewコンテナを作ることができます

は、私は次のコード、やることができたものです。

enter image description here

私が達成したい何、その中にブラックボックスバウンスではなく、テーブルを持つことです。

のView Controllerの.mの私のviewDidLoad:あなたはそのためにUIScrollViewのを使用していない理由を

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

//General View Setup 
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"backgroundimage.png"]]; 
    self.view.backgroundColor = background; 


//Table View Data 
    listOfItems = [[NSMutableArray alloc] init]; 
    NSArray *appleComputers = [NSArray arrayWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil]; 
    NSDictionary *appleComputersDict = [NSDictionary dictionaryWithObject:appleComputers forKey:@"Computers"]; 
    NSArray *otherComputers = [NSArray arrayWithObjects:@"HP", @"Dell", @"Windows", @"Sony", @"Ivory", @"IBM", nil]; 
    NSDictionary *otherComputersDict = [NSDictionary dictionaryWithObject:otherComputers forKey:@"Computers"]; 
    [listOfItems addObject:appleComputersDict]; 
    [listOfItems addObject:otherComputersDict]; 
self.navigationItem.title = @"Computers"; 

// Create a table 
tblSimpleTable.delegate = self; 
CGRect cgRct = CGRectMake(10, 50, 300, 300);   
tblSimpleTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStyleGrouped]; // Initilize the table 
    [tblSimpleTable setBackgroundColor:[UIColor blackColor]]; 

tblSimpleTable.sectionHeaderHeight = 30.0; 
tblSimpleTable.sectionFooterHeight = 30.0; 
tblSimpleTable.delegate = self; 
tblSimpleTable.dataSource = self; 
[self.view addSubview:tblSimpleTable]; 



//Create the header 
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)]; 
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)]; 
headerLabel.text = NSLocalizedString(@"Header for the table", @""); 
headerLabel.textColor = [UIColor whiteColor]; 
headerLabel.shadowColor = [UIColor yellowColor]; 
headerLabel.shadowOffset = CGSizeMake(0, 1); 
headerLabel.font = [UIFont boldSystemFontOfSize:22]; 
headerLabel.backgroundColor = [UIColor clearColor]; 
[containerView addSubview:headerLabel]; 
self.tblSimpleTable.tableHeaderView = containerView; 



} 

答えて

1

あなたのコード&が必要な変更を行ったことをテストしました。あなたがそれを好きだと思います。

コード:

(this is your .h file) 

#import <UIKit/UIKit.h> 

@interface tableScrollViewController : UIViewController 
     <UITableViewDelegate,UITableViewDataSource, UIScrollViewDelegate> { 

    UITableView *tblSimpleTable; 
    NSMutableArray *listOfItems; 
    NSMutableArray *appleComputers,*otherComputers; 
     UIScrollView *scrollView; 
    } 

@end 


(this is your .m file) 


- (void)viewDidLoad { 
    [super viewDidLoad]; 

scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 600)]; 
scrollView.delegate = self; 
scrollView.backgroundColor = [UIColor grayColor]; 
scrollView.contentSize = CGSizeMake(300, 800); 

appleComputers = [[NSMutableArray alloc] init]; // I made it by my style 
    [appleComputers addObject: @"iPhone"]; 
    [appleComputers addObject:@"iPod"]; 
    [appleComputers addObject:@"MacBook"]; 
    [appleComputers addObject:@"MacBook Pro"]; 

    otherComputers = [[NSMutableArray alloc] init]; 
    [otherComputers addObject: @"HP"]; 
    [otherComputers addObject:@"Dell"]; 
    [otherComputers addObject:@"Windows"]; 
    [otherComputers addObject:@"Sony"]; 
    [otherComputers addObject:@"Ivory"]; 
    [otherComputers addObject:@"IBM"]; 

self.navigationItem.title = @"Computers"; 

// Create a table 
tblSimpleTable.delegate = self; 
CGRect cgRct = CGRectMake(10, 50, 300, 600);   
tblSimpleTable = [[UITableView alloc] initWithFrame:cgRct 
           style:UITableViewStyleGrouped]; // Initilize the table 
[tblSimpleTable setBackgroundColor:[UIColor blackColor]]; 

tblSimpleTable.sectionHeaderHeight = 30.0; 
tblSimpleTable.sectionFooterHeight = 30.0; 
tblSimpleTable.scrollEnabled = NO; 
tblSimpleTable.delegate = self; 
tblSimpleTable.dataSource = self; 
[scrollView addSubview:tblSimpleTable]; 

self.view = scrollView; 

//Create the header 
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)]; 
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)]; 
headerLabel.text = NSLocalizedString(@"Header for the table", @""); 
headerLabel.textColor = [UIColor whiteColor]; 
headerLabel.shadowColor = [UIColor yellowColor]; 
headerLabel.shadowOffset = CGSizeMake(0, 1); 
headerLabel.font = [UIFont boldSystemFontOfSize:22]; 
headerLabel.backgroundColor = [UIColor clearColor]; 
[containerView addSubview:headerLabel]; 
tblSimpleTable.tableHeaderView = containerView; 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 2; 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if(section == 0) 
    return [appleComputers count]; 
else if(section == 1) 
    return [otherComputers count]; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = (UITableViewCell *)[tableView 
      dequeueReusableCellWithIdentifier:CellIdentifier]; 
if(cell == nil) 
{ 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
        reuseIdentifier:CellIdentifier] autorelease]; 
} 

if(indexPath.section == 0) 
     cell.text = [NSString stringWithFormat:@"%@“, 
             [appleComputers objectAtIndex:indexPath.row]]; 
else if(indexPath.section == 1) 
     cell.text = [NSString stringWithFormat:@"%@“, 
             [otherComputers objectAtIndex:indexPath.row]]; 

return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: 
      (NSIndexPath *)indexPath 
{ 
    // do whatever here 
} 
+1

クールうわー本当にありがとうございました!マジックのように動作します! ++++ 1! – TommyG

関連する問題