My problem is that I can't seem to get the image from my bundle to display properly. This method is in the view controller that controls the tableview. headerView is loaded with the tableview in the .nib file and contains a few UILabels (not shown) that load just fine. Any ideas?
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] setTableHeaderView:headerView];
NSBundle *bundle = [NSBundle mainBundle];
NSString *imagePath = [bundle pathForResource:@"awesome_lolcat" ofType:@"jpeg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
imageView = [[UIImageView alloc] initWithImage:image];
}
FIrst you need to figure out whether your image is loading properly. The quickest way to get an image is to use the UIImage convenience method +[UIImage imageNamed: rawImageName].
Also, is this a UITableViewController? (it's unclear, but implied).
Where is imageView being used? You create it near the bottom, but don't seem to do anything with it. You probably want to create the image view, assign it an image, and then add it as a subview to the headerView.
//this assumes that headerView is an already created UIView, perhaps an IBOutlet
UIImage *image = [UIImage imageNamed: @"awesome_lolcat.jpeg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
[headerView addSubview: [imageView autorelease]];
[[self view] setTableHeaderView: headerView];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With