I normally use xib for custom cells in TableViews
with Swift. In the dequeuereusablecellwithidentifier
, I can easily access the cell's outlets.
I am working on a project where I created a XIB for a view with a spinner in it (the spinner is custom and is a view). I load said view in my view controller and it works fine:
XIB
#import "HomeScreenView.h"
@interface HomeScreenView()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
@property (weak, nonatomic) IBOutlet UIImageView *spinner;
@end
@implementation HomeScreenView
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
}
@end
ViewController.m
HomeScreenView *homeScreen = [[[NSBundle mainBundle] loadNibNamed:@"HomeScreenView" owner:self options:nil] firstObject];
homeScreen.frame = self.view.bounds;
_loadingView = homeScreen;
[self.view addSubview:_loadingView];
In the ViewController.m
, I cannot access the outlet's spinner: for instance homeScreen.spinner
does not autocomplete.
In Swift, with custom cells, I know we load the file and the instantiate the cell and cast them. Since I don't know ObjC properly, I am a bit confused on how to process on how to access the xib's outlets.