IPad以编程方式创建UITableViewCell [英] IPad create a programmatically UITableViewCell

查看:73
本文介绍了IPad以编程方式创建UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想用这个问题杀死我的整个一天。
我设置了表的大小,但问题是我无法创建一个我想要的大小的单元格。我会把代码放进去。



实际上,单元格大小是defoult,我无法理解为什么。



on viewcontroller:我在滚动中创建10个表

   - (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];
尺寸+ = 300;
}
scroll.contentSize = CGSizeMake(5000,self.view.frame.size.height);
[self.view addSubview:scroll];
[super viewDidLoad];
[scroll release];

}

关于DynamicTableView:

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

static NSString * CellIdentifier = @细胞;

FotoCell * cell =(FotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[FotoCell alloc] initWithFrame:CGRectMake(0,0,50,90)] autorelease];
}
cell.titLabel.text = @iPhone发展会议;
cell.descLabel.text = @周六10:30;
cell.thumbnail.image = [UIImage imageNamed:@estadio.jpg];


返回单元格;在FotoCell上
}

   - (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 = kHorizo​​ntalTableSelectedBackgroundColor;

返回自我;
}


解决方案

您可能需要实现heightForRowAtIndexPath


ok, i want to kill my self, entire day with this problem. i set the tables size, but the problem is that i can not create a cell with the size i want. I will put code.

Acutally the cell size is the defoult one and i cant understand why.

on viewcontroller: i create 10 tables in a scroll

 - (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];

}

on DynamicTableView:

   -(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;
      }

on FotoCell:

     - (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;
  }

解决方案

You might need to implement heightForRowAtIndexPath

这篇关于IPad以编程方式创建UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆