2012-11-26 89 views
0

我正在使用表格视图(列表视图)那里我正在单元格中显示图像,图像显示但不是相同大小的所有不同大小。我希望所有相同高度和宽度的图像。 任何人都可以给我这个代码。 TNX ..显示表格的单元格中相同宽度和高度的图像

+0

对于使用自定义单元格或asynchrnousimageview提供帧。 –

+0

manohar我是新来的,如果可能的话给我一个链接教程或代码.. – Ninja

回答

0

这样做,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    cell=nil; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     CGRect imageFrame = CGRectMake(2, 8, 40, 40); 
     UIImage *img = [[[UIImage alloc] initWithData:data] autorelease]; 
     UIImageView *customImage = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease]; 
     customImage.image=img; 
     [cell.contentView addSubview:customImage]; 
    } 
    return cell; 
} 
+0

谢谢我可能.... – Ninja

+0

自定义图像找不到..什么是自定义图像在这里? – Ninja

+0

我编辑了我的答案。现在检查..... – Venkat

0

只是cellForRowAtIndexPath:方法类似波纹管与帧添加图像.. 你也可以使用UIImageView代替AsynchImageView

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

    static NSString *CellIdentifier = @"ImageCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
       initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] 
       autorelease]; 
    } else { 
    AsyncImageView* oldImage = (AsyncImageView*) 
      [cell.contentView viewWithTag:999]; 
    [oldImage removeFromSuperview]; 
    } 

    CGRect frame; 
    frame.size.width=75; frame.size.height=75; 
    frame.origin.x=0; frame.origin.y=0; 
    AsyncImageView* asyncImage = [[[AsyncImageView alloc] 
       initWithFrame:frame] autorelease]; 
    asyncImage.tag = 999; 
    NSURL* url = [imageDownload 
       thumbnailURLAtIndex:indexPath.row]; 
    [asyncImage loadImageFromURL:url]; 

    [cell.contentView addSubview:asyncImage]; 

    return cell; 
} 

See This Demo您的需求

我希望这会帮助你...

+1

感谢很多旁遮普.. – Ninja

+0

@deepak第一次尝试演示,我发布这里的链接波纹管或从这里也看到tableview与整个图像队友http://www.markj.net/iphone-asynchronous-table-image/ ... –

+0

我从另一个URL获取userid我将该userId保存在一个变量(USERID)我试过http ://abc.com/user/USERID/bookmarksdata 和http://abc.com/user/"+USERID+"/bookmarksdata,but not can take user id。 – Ninja

0

在数据源的tableview方法-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath用于图像视图 cell.imageView.frame

+0

非常感谢.. – Ninja

相关问题