0
각 행이 특정 문자로 시작하는 경우 그림을 보여주고 싶습니다. 아래 예제에서 "&"이라고합시다. 아래 코드는 첫 번째 행이 '&'으로 시작하지 않는 경우에만 작동하는 것으로 보입니다. 첫 번째 행에 '&'이 있으면 모든 행에 그림이 표시됩니다. 뭐가 문제 야? 첫 번째 cell
가 나중에 재사용 할 수 있기 때문에UITableView의 각 행을 개별적으로 평가하십시오. iPhone
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
}
if ([[[array objectAtIndex:(indexPath.row)] substringToIndex:1] isEqualToString:@"&"])
{
cell.textLabel.text = [array objectAtIndex:(indexPath.row)];
cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1];
cell.imageView.image = [UIImage imageNamed:@"picture.png"];
return cell;
}
else
{
cell.textLabel.text = [array objectAtIndex:(indexPath.row)];
cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1];
return cell;
}
}