UITableView Cells的图像

时间:2012-02-16 16:45:51

标签: objective-c ios xcode uitableview ios4

我的一个应用程序具有图像属性作为UITableView中的单元格的背景,在测试时,每件事都很好,图像和单元格高度完全按照代码测试,但是当它上传时,我试图下载它多次通过iphone,ipad,细胞被拉伸并且完全测试时应用的措施不同,图像根本不清楚,应用程序包含2种尺寸的图像(另一种是视网膜尺寸@ 2x)我不知道什么是这个问题或什么我失踪了,我正在使用XCode 4.2, 请指教,

感谢您的快速回复, 好吧,它的应用程序内购买包含很多专辑,这些专辑位于每个有合适图像的视图单元格中,下载时,图像会发生变化,uitableview会自动刷新,首先将图像设置在数组中( viewDidLoad中)

UIImage *awwal = [UIImage imageNamed:@"album-01.png"];
    UIImage *teni = [UIImage imageNamed:@"album-02.png"];
    UIImage *telet = [UIImage imageNamed:@"album-03.png"];
    UIImage *rabee = [UIImage imageNamed:@"album-04.png"];
    UIImage *akhir = [UIImage imageNamed:@"album-05.png"];
    UIImage *ba3do = [UIImage imageNamed:@"album-zaman.png"];
    UIImage *aatiha = [UIImage imageNamed:@"album-tarab.png"];
    UIImage *j3ala = [UIImage imageNamed:@"album-monawaa.png"];

    NSMutableArray *images = [[NSMutableArray alloc] initWithObjects: awwal, teni, telet, rabee, akhir, ba3do, aatiha, j3ala, nil];
 self.AlbumsImages = images;
    [images release];'

以及加载tableView的那些

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellIdentifier";
   // NSLog(@"%@",AlbumsImages);
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
     NSUInteger row = [indexPath row];
    NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *myPath = [myPathList objectAtIndex:0];
    NSString* storagePath = [myPath stringByAppendingPathComponent:@"purchasedAlbums.plist"];
    NSArray* valueList = [[NSArray alloc] initWithContentsOfFile:storagePath];

    UIImage *change1 = [UIImage imageNamed:@"playalbum-06.png"];
    UIImage *change2 = [UIImage imageNamed:@"playalbum-07.png"];
    UIImage *change3 = [UIImage imageNamed:@"playalbum-08.png"];
    UIImage *change4 = [UIImage imageNamed:@"playalbum-09.png"];
    UIImage *change5 = [UIImage imageNamed:@"playalbum-11.png"];
    UIImage *change6 = [UIImage imageNamed:@"playalbum-12.png"];
    UIImage *change7 = [UIImage imageNamed:@"playalbum-10.png"];
    UIImage *change8 = [UIImage imageNamed:@"playalbum-13.png"];

    int i;
    for (i = 0; i <= [AlbumsImages count]; i++) {


    if ([[valueList objectAtIndex:i+1] intValue]) {
        if (i == 0) {
            [AlbumsImages replaceObjectAtIndex:0 withObject:change1];
        }
        if (i == 1) {
            [AlbumsImages replaceObjectAtIndex:1 withObject:change2];
        }
        if (i == 2) {
            [AlbumsImages replaceObjectAtIndex:2 withObject:change3];
        }
        if (i == 3) {
            [AlbumsImages replaceObjectAtIndex:3 withObject:change4];
        }
        if (i == 4) {
            [AlbumsImages replaceObjectAtIndex:4 withObject:change5];
        }
        if (i == 5) {
            [AlbumsImages replaceObjectAtIndex:5 withObject:change6];
        }
        if (i == 6) {
            [AlbumsImages replaceObjectAtIndex:6 withObject:change7];
        }
        if (i == 7) {
            [AlbumsImages replaceObjectAtIndex:7 withObject:change8];
        }

    }
}
        //cell.textLabel.text = [AlbumsView objectAtIndex:row];
    cell.imageView.image = [AlbumsImages objectAtIndex:row];
    cell.tag=row+1;
    return cell;
}

其中change1,2,3 .....是下载相册时替换的图像。

1 个答案:

答案 0 :(得分:-1)

仅使用名称,而不是扩展名。

UIImage *change1 = [UIImage imageNamed:@"playalbum-06"];