I have a table view and UIView.Table view cell is having cells with image.I want when perticuler cell is selected the corresponding image should appear in “UIImage object” in UIView.
In table view class:
//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;
}
}
In UIView, LoadView method adding image like following:
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];
In above code, I’m converting image to NSString([UIImage imageNamed:imageNamedContent]) – Is this correct?
If not, How can I do this?
Note: Segue is working fine if I’m passing table cell’s text to a label in UIView.
Hope my question is clear.
Change:
Into:
Also you need to get the image of the current cell and send it with the performSegueWithIdentifier:
Then you need to update your prepareForSegue method: