0

uitableviewcell accessoryview画像が含まれているかどうかを確認することはできますか?

例えば

 if([self.tableView cellForRowAtIndexPath:indexPath].accessoryView == [UIImage  imageNamed:@"selected.png"] )  

このように、または別の方法でこれを行うものもあります。
ありがとうございました

4

4 に答える 4

1

デフォルトでは、accessoryView は null になります。

確認できます-

if (self.tableView.accessoryView) {

     // An image is present
}
于 2011-06-09T10:51:59.283 に答える
0

私のアプリでは、カスタム セルを作成してから、imageView を contentView に追加しました。

しかし、あなたの要件のために、あなたはこのようなことをすることができます

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        cell.accessoryView = imageView];
        imageView.tag = 3;
        [imageView release];
    }
    NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
    UIImageView *imageView;
    for (UIView *subview in subviews) 
    {
        if([subview isKindOfClass:[UIImageView class]] && subview.tag == 3);
            imageView = [subview copy];
    }
    [subviews release];

   if([selectedArray containsObject:indexPath])
        imageView.image = [UIImage imageNamed:@"Selected.png"];
    else
        imageView.image = [UIImage imageNamed:@"Unselected.png"];
}

そして、このメソッドで同じことを行い、imageView オブジェクトを取得します

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
于 2011-06-09T10:46:30.030 に答える
0

初め:

if([self.tableView cellForRowAtIndexPath:indexPath].accessoryView == [UIImage imageNamed:@"selected.png"] )

これは間違っています... acessaryview は画像ではなく、UIView です。

以下を確認します。

if(nil != [self.tableView cellForRowAtIndexPath:indexPath].accessoryView)
{
  // It has got something in it... 
}
else
{
 //create an accessary view....
}
于 2011-06-09T10:56:45.217 に答える
0

これは、各セルにチェックボックスを使用して複数選択テーブルビューを実装する方法です

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [disclosureButton setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12.0]];
    [disclosureButton setBackgroundImage:[UIImage imageNamed:@"checkboxoff.png"] forState:UIControlStateNormal];
    disclosureButton.tag = 0;
    [disclosureButton setFrame:CGRectMake(0,0, 30,30)];
    [disclosureButton addTarget:self action:@selector(select:event:) forControlEvents:UIControlEventTouchUpInside];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell.textLabel setUserInteractionEnabled:YES];
        [cell setImage:[UIImage imageNamed:@"bluemappointer.png"]];
        [cell setAccessoryView:disclosureButton];
    }
    else{
        int n = indexPath.row;
        if([selectedPlaces objectForKey:indexPath] != nil){
            disclosureButton.tag = 1;
            [disclosureButton setBackgroundImage:[UIImage imageNamed:@"checkboxon.png"] forState:UIControlStateNormal];
            [cell setAccessoryView:disclosureButton];
        }
        else{
            [disclosureButton setBackgroundImage:[UIImage imageNamed:@"checkboxoff.png"] forState:UIControlStateNormal];
            disclosureButton.tag = 0;
            [cell setAccessoryView:disclosureButton];
        }
    }

    NSString *name = [tableData objectAtIndex:indexPath.row];
    [cell.textLabel setText:name];

    return cell;
}
于 2012-10-16T16:13:05.770 に答える