2011-11-05 121 views
1

你好,我使用EGOImageView惰性圖像加載。我在UITable視圖上使用相同的代碼。 首先我正在配置的單元格,然後配合使用tableviewCellWithReuseIdentifier返回cell.I正在使用的代碼:如何添加懶惰的圖像加載到UIimageview

這是我tableviewCellWithReuseIdentifier我在哪裏用標籤定義的UIImageView:

- (UITableViewCell *)tableviewCellWithReuseIdentifier:(NSString *)identifier 

{

if([identifier isEqualToString:@"UICell"]) 
{ 
    UITableViewCell *uiCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease]; 

    uiCell.textLabel.textAlignment = UITextAlignmentCenter; 
    uiCell.textLabel.font = [UIFont systemFontOfSize:16]; 
    return uiCell; 
} 

CGRect rect; 

rect = CGRectMake(0.0, 0.0, 320.0, 70.0); 


UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:rect reuseIdentifier:identifier] autorelease]; 
// [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton]; 
cell.selectionStyle =UITableViewCellSelectionStyleNone; 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 70.0)]; 
imageView.tag = BG_Image; 
[cell.contentView addSubview:imageView]; 
[imageView release]; 
    return cell; 

}

,這我在哪裏構成單元的功能:

-(void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath 

{

UIImageView *imageView = (UIImageView *)[cell viewWithTag:BG_Image]; 
imageView.image = [UIImage imageNamed:@"event_box_bg.png"]; 

}

,這是我的自我形象代碼初始化後,我想知道如何使用這個代碼,並在那裏

EGOImageView *_eventImageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

請幫助..

Tha NKS,

回答

2

在你的方法tableviewCellWithReuseIdentifier添加EGOImageView到cell.ContentView你已經發布的代碼。

像這樣

- (UITableViewCell *)tableviewCellWithReuseIdentifier:(NSString *)identifier 
{ 
    if([identifier isEqualToString:@"UICell"]) 
    { 
     ... 
    } 
    CGRect rect = CGRectMake(0.0, 0.0, 320.0, 70.0); 
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:rect reuseIdentifier:identifier] autorelease]; 
    cell.selectionStyle =UITableViewCellSelectionStyleNone; 

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 70.0)]; 
    // you can assign the static background image right here 
    imageView.image = [UIImage imageNamed:@"event_box_bg.png"]; 
    [cell.contentView addSubview:imageView]; 
    [imageView release]; 

    // Create an EGOImageView 
    EGOImageView * egoImageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
    egoImageView.tag = EGO_Image; 
    [cell.contentView addSubview:egoImageView]; 
    [egoImageView release]; 

    return cell; 
} 

並在configureCell

-(void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath 
{ 
    EGOImageView *egoImageView = (EGOImageView *)[cell viewWithTag:EGO_Image]; 
    egoImageView.imageURL = [NSURL URLWithString:@"http://....jpg"]; 
} 

假設:您運行UITableViewDataSource這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"YourTableViewCellID"] 
    if (cell == nil) 
    { 
      cell = [self tableviewCellWithReuseIdentifier:@"YourTableViewCellID"]; 
    } 
    [self dataSource configureCell:cell forIndexPath:indexPath]; 

    return cell; 
} 
+0

感謝它爲我工作... – gaurav