0

表のセルにテキスト以外の画像を表示したい。一般と課題の2つのセクションがあります。今、私は割り当ての横に画像を表示したいだけで、一般セクション以外の画像は表示しません。次のコードは、[割り当て]セクションの画像を表示してから、[一般]セクションの画像を繰り返します。誰かがこれを達成する方法を私に助けてもらえますか?

//ビューをロードした後、通常はペン先から追加のセットアップを行うためにviewDidLoadを実装します。-(void)viewDidLoad {

    staffImages = [[NSMutableArray alloc] init];

    NSArray *arrTemp1 = [[NSArray alloc] initWithObjects:@"TRANSPORTATION",@"ROOMS",@"ACTIVITIES",nil];
    NSArray *arrTemp2 = [[NSArray alloc] initWithObjects:@"CHAT",@"SEARCH",@"CALL",@"MORE",nil];

    NSDictionary *temp =[[NSDictionary alloc] initWithObjectsAndKeys:arrTemp1,@"Assignments",arrTemp2,
                                                                                   @"General",nil];

    //Add item images
    [staffImages addObject:@"transportation.png"];
    [staffImages addObject:@"hotel.png"];
    [staffImages addObject:@"activities.png"];


    //Set the title
    self.navigationItem.title = @"STAFF ASSIGNMENTS";
    self.tableContents=temp;
    [temp release];

    self.sortedKeys =[self.tableContents allKeys];
    [arrTemp1 release];
    [arrTemp2 release];

    [super viewDidLoad];
}


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

    NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];

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

        }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];

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

    return cell;
    }
4

3 に答える 3

1
NSMutableData *data=[NSMutableData dataWithContentsOfURL:[NSURL URLWithString:[NSMutableString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row]objectForKey:@"LINK"]]]];

//NSLog(@"%@",data);

UIImage *img=[UIImage imageWithData:data];

cell.imageView.image=img;

これが最善の方法です

于 2012-10-30T13:03:22.343 に答える
0

一般的なセクションがセクション0(つまり最初のセクション)であると仮定します

   if (indexPath.section == 1) {
    cell.imageView.image = [UIImage imageNamed:[staffImages objectAtIndex:indexPath.row]];

   }
于 2011-04-08T18:18:19.957 に答える
0

indexPathのセクションを確認する必要があります。おそらく、セクションチェックを使用して、セルのテキストが正しい値に設定されていることを確認する必要があります。

//You do not need to actually define this value
//this is just for naming purposes
#define SECTION_ASSIGNMENTS 0

...

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

    NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];

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

        }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
    if(indexPath.section == SECTION_ASSIGNMENTS)
    {
        cell.imageView.image = [UIImage imageNamed:[staffImages objectAtIndex:indexPath.row]];
    }
    return cell;
}
于 2011-04-08T18:18:57.503 に答える