2011-12-10 56 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

相關問題