I have a an outlet to a UIView that is going to change pretty often so in order to be able to manage memory and everything I figured I'd be able to do the following:
I though I should be able to assign infoView to self.infoView but this is not working. I can prove that everything is hooked up in IB by addming infoView as a subview to self.infoView.
I don't like this approach as much though as it means I have to remove all the subviews before creating and adding a new subview.
Should the above code work? If not, can someone please help me understand why not? I though I would be able to use this the same way as UITableViews tableHeaderView property.
Code:
@interface GalleryViewController : UIViewController {
UIView *_infoView;
}
@property (nonatomic, retain) IBOutlet UIView *infoView;
- (void) updateGalleryHeaderView;
@end
/////////// .m
- (void) galleryHeaderView {
// So I'm not just adding more and more sub views.
for (UIView *view in [self.infoView subviews]) {
[view removeFromSuperview];
}
UIView *infoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 280, 25)];
infoLabel.text = @"Some text";
[infoView addSubview: infoLabel];
self.infoView = infoView; // <<<<< This doesn't work.
// [self.infoView addSubview:infoView]; <<< This does work.
[infoLabel release];
[infoView release];
}
I though I should be able to assign infoView to self.infoView but this is not working. I can prove that everything is hooked up in IB by addming infoView as a subview to self.infoView.
I don't like this approach as much though as it means I have to remove all the subviews before creating and adding a new subview.
Should the above code work? If not, can someone please help me understand why not? I though I would be able to use this the same way as UITableViews tableHeaderView property.