Question

I declare a a uiview in my header file of a uiviewcontroller like so:

@property (strong, nonatomic) UIView *loadLoading;

And initiate itin viewdidload:

loadLoading = [[UIView alloc] initWithFrame:self.view.bounds];
loadLoading.backgroundColor = [UIColor blueColor];
[self.view addSubView:loadLoading];

This works fine. But at another point in my program i want to remove this subview. But for some reason, it doesnt get removed.

NSLog(@"%@",loadLoading.backgroundColor);
[loadLoading removeFromSuperview];

(I know it gets to that point and loadLoading is accessible because the log does work.

No correct solution

OTHER TIPS

If you are getting the NSLog(@"%@",loadLoading.backgroundColor); worked.

Then this code [self.loadLoading removeFromSuperview]; should be work, else there is some weird bug.

Here is another approach: Add a tag to the view when you add it to the parentView.

loadLoading = [[UIView alloc] initWithFrame:self.view.bounds];
[loadLoading setTag:7];

Use that tag to remove it from the parentView.

[[self.view viewWithTag:7] removeFromSuperView];

Found the issue.

I didnt provide enough details in my question. I was calling this method from notificationcenter, which loads on a different thread. So i had to first do performSelectorOnMainThread which worked

Try:

[self.loadLoading removeFromSuperview];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top