When I try to run the program compiles and I don't receive any errors. Everything works as it should except that the image is not showing on the View Controller. Can't figure where why the image is not showing. I appreciate any inputs. Here is my code:
ViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowItemDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ItemDetailViewController *destViewController = segue.destinationViewController;
destViewController.itemDesc = [listItems objectAtIndex:indexPath.row];
destViewController.itemName = [listTimes objectAtIndex:indexPath.row];
destViewController.pictureImageView = [listImages objectAtIndex:indexPath.row];
}
ItemDetailViewController.h
#import <UIKit/UIKit.h>
@interface ItemDetailViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *itemLabel;
@property (nonatomic, strong) IBOutlet UILabel *itemTitle;
@property (nonatomic, strong) NSString *itemName;
@property (nonatomic, strong) NSString *itemDesc;
@property (nonatomic, strong) IBOutlet UIImageView* pictureImageView;
@property (nonatomic, strong) UIImage *picImageView;
@end
ItemViewController.m
#import "ItemDetailViewController.h"
@interface ItemDetailViewController ()
@end
@implementation ItemDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.itemLabel.text = self.itemName;
self.itemTitle.text = self.itemDesc;
self.pictureImageView.image = self.picImageView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
At the time of viewDidLoad
, chances are that self.picImageView
is empty. Please check that.
Then, in order to set the picture, write a function like:
-(void) setPicImageView: (UIImage*) picImage{
self.picImageView = picImage;
self.pictureImageView.image = picImage;
}
This should solve your problem.
Hope this helps.
Try this on your prepare for segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowItemDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ItemDetailViewController *destViewController = segue.destinationViewController;
destViewController.itemDesc = [listItems objectAtIndex:indexPath.row];
destViewController.itemName = [listTimes objectAtIndex:indexPath.row];
destViewController.picImageView = [listImages objectAtIndex:indexPath.row];
}
And in your viewDidLoad try this:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.itemLabel.text = self.itemName;
self.itemTitle.text = self.itemDesc;
self.pictureImageView.image = self.picImageView;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.