0

私のcellForRowAtIndexPathで

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
//...do cell setup etc.

            UIImage *iconthumbNail = [UIImage imageNamed:@"icon.png"];
        UIImageView * iconimgView = [[UIImageView alloc] initWithFrame:CGRectMake(265, 34, 25, 25)];
        [iconimgView setImage:iconthumbNail];
        //imgView.image = thumbNail;
        [cell addSubview:iconimgView];
        [iconimgView release];
      // add a few more UIImageViews to the cell
    }

だから私の中で

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
[tableView deselectRowAtIndexPath:indexPath animated:NO];

UITableViewCell * theCell = [tableView cellForRowAtIndexPath:indexPath];

    for (UIView * b in cell.subviews)
{
    if ([b isKindOfClass:[UIImageView class]])
    {
        // how do I check that its 'iconImgView' so that I can change it?
    }
}

そこで、cellForRowAtIndexPathにUIImageViewを追加し、そのテーブルセルが選択されたときに、セル内の画像の1つ「iconImgView」を変更したいのですが、このセルに存在する他のUIImageViewからこのUIImageViewを識別するにはどうすればよいですか?

どうもありがとう、-コード

4

2 に答える 2

2

そのアプローチを使用する代わりに、私はUIImageViewあなたが探しているタグを割り当てます。

iconimgView.tag = 1;

次に、didSelectRowAtIndexPathメソッドで次を使用します。

UIImageView *iconimgView = (UIImageView *)[cell viewWithTag:1];

それでも自分のやり方でやりたい場合は、次のようにすることができます。

if ([b isKindOfClass:[UIImageView class]]) {
    UIImageView *myView = (UIImageView *)b;
    if ([b.image isEqual:[UIImage imageNamed:@"yourImageName"]]) {
        // Do your stuff
    }
}
于 2012-10-13T14:24:15.273 に答える
0

選択したセルの画像を変更することが唯一の目標である場合、これをより効率的に行うことができます。あなたがしなければならないのは、cellsimageViewプロパティへの読み取り/書き込みです。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];
    [[theCell imageView] setImage:[UIImage imageNamed:@"someImage.jpg"]];//altering the existing image
    UIImageView *myImageView = theCell.imageView;//read the image property of the cell
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
于 2012-10-13T14:41:05.947 に答える