2011-11-05 79 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