我不能为我的观点指定黑色背景

时间:2011-05-05 13:07:03

标签: ios ipad

我无法将黑色背景指定给我的表格行或添加的ImageViews。 (每行有多个imageViews。背景总是白色的。这是我的代码:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
cell.textLabel.text = [self wordAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellEditingStyleNone;
cell.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0];

//NSString *url = self.imageURL;
//dispatch_queue_t callerQueue = dispatch_get_current_queue();

dispatch_queue_t downloadQueue = dispatch_queue_create("Flickr downloader in Photo", NULL);
dispatch_async(downloadQueue, ^{
    NSData *image = [FlickrFetcher imageDataFromPhotoId:@"2654899252"];
    NSData *image2 = [FlickrFetcher imageDataFromPhotoId:@"2654072649"];
    NSData *image3 = [FlickrFetcher imageDataFromPhotoId:@"2654072293"];        /*dispatch_async(callerQueue, ^{
        processImage(imageData);
    });*/

    UIImageView *imageView = nil;

    if(image) imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: image]];

    UIImageView *imageView2 = nil;
    if(image2) imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageWithData: image2]];

    UIImageView *imageView3 = nil;
    if(image3) imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageWithData: image3]];

    imageView.frame = CGRectMake(0.0, 0.0, 220, 200);
    imageView2.frame = CGRectMake(240.0, 0.0, 220, 200);
    imageView3.frame = CGRectMake(480.0, 0.0, 220, 200);

    imageView.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0];
    imageView2.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0];
    imageView3.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 1.0];



    [cell addSubview:imageView];
    [cell addSubview:imageView2];
    [cell addSubview:imageView3];

    [imageView release];
    [imageView2 release];
    [imageView3 release];
});
dispatch_release(downloadQueue);

1 个答案:

答案 0 :(得分:0)

好的尝试添加:

cell.contentView.backgroundColor = [UIColor blackColor];
cell.backgroundView.backgroundColor = [UIColor blackColor];

通过将tableView.separatorStyle设置为UITableViewCellSeparatorStyleNone

来删除行

您的ViewController中应该有一个UITableView。如果您使用UITableViewController在viewDidLoad方法中设置该属性:

-(void) viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}