Reputation: 7004
At least I think it's a basic problem. I just started working with views programmatically.
In RouteCaptureViewController.h:
@property (strong, nonatomic) IBOutlet UIView *routeCaptureSuperView;
@property(nonatomic, weak) IBOutlet UIImageView *captureImageView;
@property(nonatomic, retain) IBOutlet UIImageView *previewImageView;
@property (weak, nonatomic) IBOutlet UIView *captureRouteButtonView;
In my storyboard:
All of the outlets are properly connected, I checked.
I'm implementing addSubview in a method as such and nothing happens:
[self.routeCaptureSuperView addSubview:self.captureRouteButtonView];
[self.routeCaptureSuperView addSubview:self.captureImageView];
The following lines worked previously in the code:
[self.captureImageView removeFromSuperview];
[self.captureRouteButtonView removeFromSuperview];
And I know self.routeCaptureSuperView
is not nil
from an NSLog.
Upvotes: 0
Views: 3017
Reputation: 90127
If I understood you correctly and you removed the views to add them again later I can make an educated guess:
In the moment you send removeFromSuperview
to your views they get deallocated because they are declared as weak
only.
Weak means that the property will be nil'd if the object is deallocated because the last strong relationship to that object is released.
The parent view is the object that keeps the last strong relationship to those two views.
Try to change weak
to strong
in the @property
declaration of the two subviews.
Upvotes: 1