I am using data task to display textual data from external server via JSON File. which is working pretty fine
and I am using AFNetworking's file #import "UIImageView+AFNetworking.h"
to download image from above extracted data in Tableview's Cell declaration it also working pretty fine.
But when selecting a row to pass selected rows Image via Segue to another view controller it giving error,
Here is my code for Tableview's cell which is pretty fine & Displaying textual & Image data
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"maincell" forIndexPath:indexPath];
Categories * CategoryObject;
CategoryObject = [categoryArray objectAtIndex:indexPath.row];
cell.textLabel.text = CategoryObject.categoryTitle;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell Image...
NSURL *url = [NSURL URLWithString:CategoryObject.categoryImage];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"];
__weak UITableViewCell *weakCell = cell;
[cell.imageView setImageWithURLRequest:request placeholderImage:placeholderImage success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakCell.imageView.image = image;
[weakCell setNeedsLayout];
} failure:nil];
return cell;
}
Now take a look at Segue code which giving error
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showAnotherView"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
DetailImageViewController *destViewController = segue.destinationViewController;
destViewController.imageName = [ UIImageView objectAtIndex:indexPath.row.image];
}
}
my code giving error
no known class method for selector
objectAtIndex:
in last line of the code
destViewController.imageName = [ UIImageView objectAtIndex:indexPath.row.image];
The thing I want to accomplish is to resolve this error and to pass above cached image which is downloaded via AFNetworking and to pass that image in segue to display in next view controller. could anyone help me out?
Looking at your code, it seems like you are accessing objectAtIndex:
method on UIImageView
which don't have the method unless you have category class extending UIImageView
. If you are going to handle the raw selection, it should be something like this,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showAnotherView"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
DetailImageViewController *destViewController = segue.destinationViewController;
destViewController.imageName = Cell.imageView.image;
}
}
Hope this help.