-1

ViewController にテーブルがあります。このテーブルでは、webService と CoreData から情報を取得します。この情報は各行に表示されます。各行を押すと、詳細ビ​​ューに移動して画像を作成します。

私はカードを持っていて、各カードには異なるスタンプがあります。detailView に行くとき、この画像を作成したいです。つまり、カードに 2 つのスタンプがある場合は 2 つの画像を作成し、3 つのスタンプがある場合は 3 つの画像を作成したいということです。 、

この実装で私を助けてください、事前に感謝します!

Web サービスから取得した情報は次のとおりです。

createdAt = 1362412409;
id = 2;
stampNumber = 2;
   },
   {
        createdAt = 1362069567;
        id = 1;
        stampNumber = 10;
   }

ここに私のコードがあります:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
    *)indexPath
{
    static NSString *CellIdentifier = @"CardsCell";
    CardCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    
    if (cell == nil){
         NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CardCell" owner:nil 
    options:nil];
        for (id currentObject in objects)
                    {
                        if([currentObject isKindOfClass:[UITableViewCell class]])
                        {
                            cell = (CardCell *) currentObject;

                            break;
                        }
                    }
    }
    card = self.cards[indexPath.row];

    cell.stampId.text = [[NSString alloc] initWithFormat:@"%@",card.stampNumber];
    cell.createdAt.text = [[NSString alloc] initWithFormat:@"%@",card.createdAt];
    cell.CardId.text = [[NSString alloc] initWithFormat:@"Carte %d",(indexPath.row+1)];
    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
     *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"cardDetail" object:nil 
    userInfo:nil];
}

私の質問は、スタンプに基づいてプログラムでこの写真を作成する方法です..

編集: 私はこの画像を持っています:

UIImageView *stampIMG = [[UIImageView alloc] initWithFrame:self.view.frame];
stampIMG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]];
stampIMG.frame = CGRectMake(0, 0, 122, 122);

この画像だけ使いたい

4

1 に答える 1

0

画像のNSDataではなく、画像の場所へのパスを保存する必要があります。次に、stampIdを使用してその画像パスを取得し、画像に読み込みます。イメージがサーバー上にある場合は、イメージをダウンロードします。画像をNSDataとしてCoreDataに保存することもできますが、このBLOBは大きくなる可能性があるため、通常は画像へのパスを保存する方が適切です。したがって、CoreDataでは、stampIdとImagePathを持つオブジェクトStampを持つことができます。次に、stampIdでオブジェクトをフェッチしてから、オブジェクトからimagePathを取得します。

スタンプIDで画像を取得するには、おそらくこのようなものを試してみます。イメージがダウンロードされている場合は、ドキュメントディレクトリとメインバンドルを置き換えます。

NSFetchRequest * stampById = [[NSFetchRequest alloc] init];
[stampById setEntity:[NSEntityDescription entityForName:@"Card" inManagedObjectContext:self.managedObjectContextBKG]];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"stampId == %@", stampId];
[stampById setPredicate:predicate];

NSError *error = nil;
NSArray * stampResults = [self.managedObjectContext executeFetchRequest:stampById error:&error];

if(nil != stampResults && [stampResults count]){
    Stamp *stamp = [stampResults objectAtIndex:0];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource: stamp.imagePath ofType:@"png"]];
} 
于 2013-03-07T17:55:36.927 に答える