UIImageView does not appear in UITableView header

My problem is that I cannot seem to have the image from my package display correctly. This method is located in the view controller, which controls the table view. The headerView is loaded with a table view in the .nib file and contains several 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]; } 
+4
source share
4 answers

If you have already created a socket and connected it to a view in Interface Builder, you should use this view and not create a UIImageView on the fly.

 //this assumes that headerView is an already created UIView, perhaps an IBOutlet //also, imageViewOutlet is an IB outlet hooked up to a UIImageView, and added as //a subview of headerView. //you can also set the image directly from within IB imageViewOutlet.image = [UIImage imageNamed: @"awesome_lolcat.jpeg"]; [[self view] setTableHeaderView: headerView]; 
+4
source

FIrst you need to find out if the image is loading correctly. The fastest way to get an image is to use the UIImage + [UIImage imageNamed: rawImageName] convenience method.

Also, is it a UITableViewController? (this is unclear, but implied).

Where is imageView used? You create it at the base, but it seems you are not doing anything with it. You might want to create an image view, assign an image to it, and then add it as a subquery 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]; 
+4
source

Adding a subquery worked programmatically, but it is not properly associated with the UIImageView in Interface Builder. The view I created (I think) is correctly connected with the UIView output in my UITableViewController, but when I start my ImageView, it creates a new view instead of putting the image in the view that I already created.

Thanks for your reply.

0
source
0
source

Source: https://habr.com/ru/post/1277775/


All Articles