Загрузка отдельных изображений из массива в UITabeView - PullRequest
1 голос
/ 08 января 2011

Я пытаюсь загрузить три разных изображения из массива в соответствующие ячейки в UITable. Пока у меня есть следующий код, который создает хорошие сбои при запуске t. Я могу помочь мне, я был бы очень благодарен.

- (void)viewDidLoad {
 NSArray *array = [[NSArray alloc] initWithObjects:@"Icon Nightclub", @"Smyhts Bar",
       @"Synotts",nil];
 self.listData = array;


 NSArray *picArray = [[NSArray alloc] initWithObjects:@"ArrowLeftDefault.png", @"ArrowRightDefault.png",
       @"events.png",nil];
 self.picData = picArray;


 [array release];
 [picArray release];
 [super viewDidLoad];

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ 
 return [listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

 if (cell == nil) {
  cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
 }

 NSUInteger row = [indexPath row];
 cell.textColor = [UIColor grayColor];
 cell.textLabel.text = [listData objectAtIndex:row];
 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

 cell.imageView.image = [picData objectAtIndex:indexPath.row];

 return cell;

}

1 Ответ

4 голосов
/ 08 января 2011

изменение:

cell.imageView.image = [picData objectAtIndex:indexPath.row];

примерно так:

cell.imageView.image = [UIImage imageNamed:[picData objectAtIndex:indexPath.row]];

Пояснение: Поскольку picData NSArray содержит NSString s, вы передавали объект NSString в cell.imageView.image, когда он действительно ожидает объект UIImage. Вот почему теперь он создает изображение и передает его. (imageNamed: метод обналичивает изображение)

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