ios - iPad 以编程方式创建一个 UITableViewCell

标签 ios ipad uitableview

好吧,我想为这个问题自杀一整天。 我设置了表格大小,但问题是我无法创建具有我想要的大小的单元格。我会放代码。

实际上单元格大小是默认值,我不明白为什么。

在 View Controller 上:我在滚动中创建了 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];
    size+=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 = @"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 上:

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

最佳答案

您可能需要实现 heightForRowAtIndexPath

关于ios - iPad 以编程方式创建一个 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8123430/

相关文章:

ios - TableViewController 没有正确向上滚动

ios - 增加 iPad 上的 UIAlertView 大小

ios - 解析查询后重新加载 tableView(串行队列?)

ios - UITableViewCell 中的多个点击手势

ios - AWS-Cognito 和 DynamoDB 将如何用于移动开发-iOS-Swift

ios - iOS,RESTKit,如何设置请求超时

ios - UISearchController 搜索框在点击时向下移动

ios - Cocoa Pods 未在应用程序内部更新

php - 通过 Jquery/Javascript 在 iPad 和 iPad2 之间检测?

ios - 自定义分组 UITableView