-1

我有一个表视图和UIView.Table View Cell在选择Perticuler小区时,可以使用映像的小区。在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 回答