2011-12-10 55 views

回答

6

继承UITableViewCell来制作自定义单元格。可以说它叫做MyCustomCell

使用它像下面

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

    // In your case it has to be the custom cell object here. 

    MyCustomCell *cell = (MyCustomCell*)[tableView dequeueReusableCellWithIdentifier:@"AnIdentifierString"]; 

    if (cell == nil) 
    { 
     cell = [[[MyCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AnIdentifierString"] autorelease]; 
    } 

    //use your cell here 
    // cell.textLabel.text = @"This text will appear in the cell"; 
    return cell; 
} 

你可以重写的init与MyCustomCell风格的多幅图像

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 

    //change frame sizes to palce the image in the cell 
     UIImageView * thumbnail1 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)]; 
     thumbnail1.image = [UIImage imageNamed:@"Icon.png"]; 
     [self addSubview:thumbnail1]; 

     UIImageView * thumbnail2 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)]; 
     thumbnail2.image = [UIImage imageNamed:@"Icon.png"]; 
     [self addSubview:thumbnail2]; 

     UIImageView * thumbnail3 = [[UIImageView alloc] initWithFrame:CGRectMake(17, 12, 62, 62)]; 
     thumbnail3.image = [UIImage imageNamed:@"Icon.png"]; 
     [self addSubview:thumbnail3]; 

    } 
    return self; 
} 
+0

如下,请格式化代码,让别人了解 –

+0

好,我发现了一个教程[链接](http://www.icodeblog.com/2008/09/02/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-2/)谢谢。 –

+0

如果我有像第一个单元格中的数据,我有7个图像,并且我想在一个单元格中显示第一个3图像,第二个单元格中显示另外3个图像,第三个单元格中剩余1个图像,那么我该怎么做......?任何解决方案......? – TheMall

相关问题