изменить фон ячейки - PullRequest
1 голос
/ 17 февраля 2012

Как изменить фоновое изображение ячейки uitableview?

Я пишу этот код, он не работает.но я уверен, что в этом коде какая-то незначительная ошибка.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) 
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell setBackgroundView:[UIImage imageNamed:@"selected-bg.png"]];
}

Ответы [ 2 ]

4 голосов
/ 17 февраля 2012

Вам нужно обернуть UIImage в UIImageView, прежде чем вы сможете установить его как backgroundView:

UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]] autorelease];
[cell setBackgroundView:imageView];
3 голосов
/ 17 февраля 2012

Вы передаете неправильный параметр в setBackgroundView: функцию UITableViewCell .. Он ожидает либо экземпляр UIView, либо любой экземпляр, унаследованный от UIView.

UIImageView * myImage = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected-bg.png"]];
[cell setBackgroundView:myImage];
[myImage release];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...