-1

テーブルビューとUIViewがあります。テーブルビューセルには画像付きのセルがあります。パーティキュラーセルを選択すると、対応する画像がUIViewの「UIImageオブジェクト」に表示されます。

テーブルビュークラスの場合:

//I'm getting temp image as following(in my "cellForRowAtIndexPath" method)
  if(indexPath.row == 0)
    {
        [[cell imageView]setImage:[UIImage imageNamed:@"greekChickenSalad.png"]];
        tempImage = [UIImage imageNamed:@"greekChickenSalad.png"];
    }

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"SubRecipeDescriptionSegue"])
{
     RecipeDescriptionViewController *rdVC;
    rdVC = segue.destinationViewController;
    rdVC.parentIndexRDVC = descriptionIndexPath;
    rdVC.DescriptionLabel = (UILabel*)subRecipeSelected;
    rdVC.image = tempImage;

}

}

UIViewで、LoadViewメソッドは次のように画像を追加します。

NSData *imageDataString = UIImagePNGRepresentation(image);
NSString *imageNamedContent = [[NSString alloc]initWithBytes:[imageDataString bytes] length:[imageDataString length] encoding:NSASCIIStringEncoding];
UIImage *image1 = [UIImage imageNamed:imageNamedContent];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image1];
imageView.frame = CGRectMake(30,30, 250, 100);
[self.view addSubview:imageView];

上記のコードでは、画像をNSString([UIImage imageNamed:imageNamedContent])に変換しています-これは正しいですか?

そうでない場合、どうすればこれを行うことができますか?

注:テーブルセルのテキストをUIViewのラベルに渡す場合、Segueは正常に機能しています。

私の質問が明確であることを願っています。

4

1 に答える 1

0

変化する:

NSData *imageDataString = UIImagePNGRepresentation(image);
NSString *imageNamedContent = [[NSString alloc]initWithBytes:[imageDataString bytes] length:[imageDataString length] encoding:NSASCIIStringEncoding];
UIImage *image1 = [UIImage imageNamed:imageNamedContent];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image1];

の中へ:

UIImageView *imageView = [[UIImageView alloc]initWithImage:image];


また、現在のセルの画像を取得し、performSegueWithIdentifierで送信する必要があります。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"SubRecipeDescriptionSegue" sender:cell.imageView.image];
}

次に、prepareForSegueメソッドを更新する必要があります。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"SubRecipeDescriptionSegue"])
    {
        UIImage *selectedImage = (UIImage*)sender;

        RecipeDescriptionViewController *rdVC;
        rdVC = segue.destinationViewController;
        rdVC.parentIndexRDVC = descriptionIndexPath;
        rdVC.DescriptionLabel = (UILabel*)subRecipeSelected;
        rdVC.image = selectedImage;
    }
}
于 2012-12-18T09:05:38.467 に答える