1

セルを作成した後、セルのインデックスパスを取得するにはどうすればよいですか?uniqcell.tagを設定する必要があります。私がそれをどのように行うことができるか他のアイデアはありますか?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject
{
    ConditionCell *cell = (ConditionCell *)[tableView dequeueReusableCellWithIdentifier:[ConditionCell reuseIdentifier]];

    if ( nil == cell )
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ConditionCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else
    {
        // Reset Image
        cell.img.image = nil;
    }

理由は、別のスレッドでセルを見つける必要があるためです

[condition processImageDataWithBlock:^(NSData *imageData) {
            if (self.view.window) {
                if (cell.tag == [self.tableView indexPathForCell:cell].row)
                {
                    NSLog(@"%@",cell.tag);
                    UIImage *image = [UIImage imageWithData:imageData];
                    [condition writeToFile:imageData];
                    if (image)
                    {
                        cell.img.image = image;
                        [cell.activityIndicator stopAnimating];
                        [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[self.tableView indexPathForCell:cell]] withRowAnimation:UITableViewRowAnimationNone];
                    }
                    [condition release];
                }
            }
        }];
4

1 に答える 1

1

おそらく問題は、それが UIView であるため、メインスレッドではなく呼び出していることです-これを試してください:

- (void)someMethodToStartAsync
{
    UITableViewCell *cell = however your getting your cell;
    NSAssert(cell, @"cell was nil");
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

    [condition processImageDataWithBlock:^(NSData *imageData) {
        // do something with indexPath
    }
}

indexPath はブロック内で使用するとコピーになるため、初期化した値をブロックの外に反映させたい場合は、次のように宣言します。

_block NSIndexPath *indexPath = whatever;
于 2011-07-24T18:48:10.997 に答える