2011-11-14 48 views
0

好吧,我想杀死我自己,整天都有这个问题。 我设置表的大小,但问题是,我不能创建一个我想要的大小的单元格。我会把代码。IPad以编程方式创建UITableViewCell

Acutally cell size is defoult one and i can not understand why。

上的ViewController:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

    FotoCell *cell = (FotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[FotoCell alloc] initWithFrame:CGRectMake(0, 0, 50, 90)] autorelease]; 
    } 
     cell.titLabel.text = @"Meeting on iPhone Development"; 
     cell.descLabel.text = @"Sat 10:30"; 
     cell.thumbnail.image = [UIImage imageNamed:@"estadio.jpg"]; 


return cell; 
     } 

上FotoCell:我对DynamicTableView在滚动

- (void)viewDidLoad { 
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
scroll.pagingEnabled = NO; 
NSInteger size=50; 
for (int i = 0; i < 10; i++) { 
    DynamicTableView *table = [[[DynamicTableView alloc] initWithFrame:CGRectMake(size, 50, 254, 600) style:UITableViewStylePlain] autorelease]; 
    [table setDelegate:table]; 
    [table setDataSource:table]; 
    [scroll addSubview:table]; 
    size+=300; 
} 
scroll.contentSize = CGSizeMake(5000, self.view.frame.size.height); 
[self.view addSubview:scroll]; 
[super viewDidLoad]; 
[scroll release]; 

} 

创建10个表

 - (id)initWithFrame:(CGRect)frame{ 
[super initWithFrame:frame]; 

self.thumbnail = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,150,90)] autorelease]; 
self.thumbnail.opaque = YES; 

[self.contentView addSubview:self.thumbnail]; 

self.titLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, self.thumbnail.frame.size.height * 0.632, self.thumbnail.frame.size.width, self.thumbnail.frame.size.height * 0.37)] autorelease]; 
self.titLabel.opaque = YES; 
self.titLabel.backgroundColor = [UIColor colorWithRed:0 green:0.4745098 blue:0.29019808 alpha:0.9]; 
self.titLabel.textColor = [UIColor whiteColor]; 
self.titLabel.font = [UIFont boldSystemFontOfSize:11]; 
self.titLabel.numberOfLines = 2; 
[self.thumbnail addSubview:self.titLabel]; 

self.backgroundColor = [UIColor colorWithRed:0 green:0.40784314 blue:0.21568627 alpha:1.0]; 
self.selectedBackgroundView = [[[UIView alloc] initWithFrame:self.thumbnail.frame] autorelease]; 
self.selectedBackgroundView.backgroundColor = kHorizontalTableSelectedBackgroundColor; 

return self; 
    } 

回答

2

您可能需要实施heightForRowAtIndexPath

+0

那是 在桌上课上吧?任何想法,我可以看看呢? –

+0

Apple文档。的UITableViewDelegate。始终浏览文档。 – Dancreek

+0

thx很多人,你给我这个正确的方向。如果我可以再次打扰你,我有旋转视图的问题。我在我的所有clases方法 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation。它的回报是,但不这样做。帮帮我? :D –