Question

I have a UIView subclass with a xib called RoundedImageView, which only implements the drawRect method. The xib contains an AsyncImageView (which is a subclass of UIImageView) with an outlet. This RoundedImageView is part of a custom table view cell. In the awakeFromNib method of this cell, the RoundedImageView is not nil, but it's AsyncImageView outlet is nil. Why is this happening and how do I fix this?

Was it helpful?

Solution

After discussion with OP in chat, the issue turned out to be that the table cell / RoundedImageView was in one nib, and RoundedImageView with AsycImageView was in another. The solution was remove RoundedImageView from the cell, and load its nib in the cell's awakeFromNib method:

@implementation InviteFriendsImageVIew

- (void)awakeFromNib
{
    UINib *imageViewNib = [UINib nibWithName:@"RoundedImageView" bundle:nil];
    RoundedImageView *imageView = [imageViewNib instantiateWithOwner:nil options:nil][0];
    imageView.frame = // set frame here
    [self addSubView:imageView];
    self.roundedImageView = imageView;
}

OTHER TIPS

Somewhere you are creating an instance of the view, probably with:

RoundedImageView *v = [[RoundedImageView alloc] initWithFrame:...];

this doesn't use the NIB file. You need to load the NIB with:

UINib *nib = [UINib nibWithNibName:... bundle:nil];
NSArray *views = [nib instantiateWithOwner:... options:nil];

Then you can get the instance of RoundedImageView as:

RoundedImageView *v = views[0];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top