фоновое изображение в виде таблицы ячеек - PullRequest
0 голосов
/ 03 мая 2011

У меня есть небольшая проблема, я хотел бы изменить фоновое изображение это код

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // chemin de l'image
    NSString *img=[[NSBundle mainBundle] pathForResource:@"title" ofType:@"png"];
    UIImage *ui=[[UIImage alloc] initWithContentsOfFile:img];

    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

    cell.textLabel.text= [hadiths objectAtIndex:indexPath.row];
    [cell.textLabel setTextAlignment:UITextAlignmentCenter];
    cell.imageView.image=ui;
    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    return cell;

}

но изображение появляется и текст НЕТ ...

Ответы [ 2 ]

0 голосов
/ 03 мая 2011

Это должно работать

NSString *img=[[NSBundle mainBundle] pathForResource:@"title" ofType:@"png"];
UIImage *ui=[[UIImage alloc] initWithContentsOfFile:img]; 
UIImageView* imgView = [[UIImageView alloc] initWithImage:ui];
cell.backgroundView = imgView;
[imgView release];

OR

UIImageView* imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]] autorelease];
cell.backgroundView = imgView;

cell.backgroundView - это подкласс UIView, которому вы назначаете UIImage, который, очевидно, не является представлением, поэтому выдает ошибку.

[UIImage imageNamed:@"title.png"] загрузит изображение title.png из основного комплекта.

0 голосов
/ 03 мая 2011

cell.imageView - это значок (слева) ячейки.Фон устанавливается с помощью cell. backgroundView

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...