您好我正在使用EGOImageView进行延迟图像加载。我在UITable视图上使用相同的代码。 首先我正在配置单元格,然后使用tableviewCellWithReuseIdentifier返回单元格。我正在使用代码:
这是我的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"];
}
这是我的初始化后的EGO图像代码我想知道如何使用这个代码和
EGOImageView *_eventImageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]];
请帮助..
谢谢,
答案 0 :(得分:2)
将 EGOImageView 添加到方法 tableviewCellWithReuseIdentifier 中的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;
}
AND在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;
}