2011-09-17 15 views
-2

私は現在、ユーザーが「Apple」を選択したときにプロジェクト内のイメージをAppleのイメージビューにロードすることを希望する単純なグループ化されたUITableViewを作成しています。UITableViewとアイテムの選択

私はインターネット上でいくつかの例を見ましたが、そこに他に何があるかを見極めようとしています。

ご意見をいただければ幸いです。ありがとう。

+0

何をwillDisplayCell:forRowAtIndeaPath:ん? – user523234

+0

セルが表示される直前に呼び出されます。それは、コンテンツの変更ではなく、セルのUI変更を行う場所です。 – chown

+0

あなたがここで何を学ぼうとしているのかははっきりしない。テーブルの選択( '-tableView:didSelectRowAtIndexPath:')を検出し、 'UIImageView'(' -setImage: ')で画像を表示する操作は簡単です。どこに問題がありますか?どのようなサンプルを見ましたか?他のソリューションを探したいというサンプルはどうですか? – jemmons

答えて

0

のどちらかがcell.imageView.highlightedImage設定、またはdidSelectRowAtIndexPath方法では、いくつかの[UIImage imageNamed:@"myImage.png"]にゼロからcell.imageView.imageを変更:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *kCustomCellID = @"com.me.foo.cell"; 
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease]; 
    cell.textLabel.highlightedTextColor = [UIColor blueColor]; 
    cell.imageView.image = nil; 
    cell.imageView.highlightedImage = [UIImage imageNamed:@"myImage.png"]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(iPadRootViewControllerTableCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.imageView.contentMode = UIViewContentModeScaleAspectFit; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Do this if you didnt set the highlightedImage in cellForRowAtIndexPath 
    // [self tableView:tableView cellForRowAtIndexPath:indexPath].imageView.image = [UIImage imageNamed:@"myApple.png"]; 
} 
+0

私は私のUITableViewで7つのオプションがある場合、それは動作しますか?アップル、オレンジ、バナナ........ – Brandon

+0

うん、そうだろう。配列のobjectForIndexとしてindexPath.rowを使用してください。 – chown

関連する問題