Reputation: 3473
I made a table where I used the customcell in the table.
In the cell there are two buttons.
When a user clicks the detail button I want the thumb image to appear in the Imageview of the selected row(cell) to the other view.
When a user clicks the button the user is pushed to another view.
Please help me; how do I get the thumb image into other UIViewcontroller?
Upvotes: 2
Views: 424
Reputation: 796
In the other UIViewController that you are pushing, add a UIImageView to the XIB file of your view and link it up to something like this:
@property (nonatomic, retain) IBOutlet UIImageView *thumbImageView;
Then when you are pushing your view, set your UIImageView after you push the new view controller.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AnotherViewController *anotherViewController = [[AnotherViewController alloc] init];
[self.navigationController pushViewController:anotherViewController animated:YES];
anotherViewController.thumbImageView = [tableView cellForRowAtIndexPath:indexPath].imageView;
[anotherViewController release];
}
Upvotes: 1
Reputation: 3073
One way would be to add a method to your detail view that takes the image as a parameter for example: in your header (If your class is called DetailViewController) and assuming you have a UIImageView on the detail page.
-(DetailViewController *) initWithImage:(UIImage *)image;
in your implementation:
-(DetailViewController *) initWithImage:(UIImage *)image
{
self = [super init];
if (self)
{
self.imageView.image = image;
}
return self;
}
and to use that method:
DetailViewController* dvc = [[DetailViewController alloc] initWithImage:myImage];
[myNavigationController pushViewController:dvc animated:YES];
[dvc release]; //Don't leak
Upvotes: 1