The view has not disappeared, sometimes

advertisements

There is a very hard issue I'm trying to pursue. In the viewDidAppear: I have the following code:

if(dataSourceCount > 0)
{
    [scrollView setHidden:NO];
    UIView *ndView = [self.view viewWithTag:204];
    [ndView removeFromSuperview];
    self.noDataView = nil;
    infoBtn.hidden = NO;
}
else
{
    [scrollView setHidden:YES];
    [[NSBundle mainBundle] loadNibNamed:@"NoDataView" owner:self options:nil];
    self.noDataView.tag = 204;
    [self.view addSubview:self.noDataView];
    infoBtn.hidden = YES;
}
[super viewDidAppear:animated];

The problem occurs on if true case, very rarely and as a result on the device I can see the view that has been removed from superview - ndView.

I was thinking that viewWithTag may return nil sometimes, but this is not the case as I found out from debug. Also tried to move self.noDataView = nil to else and found the issue again.

Is there any obvious or non-obvious mistake that I'm doing here, which I'm not supposed? The idea of this code snippet is to temporarily show some other view, while data is not available.


I don't know if that solves your problem but:

  1. [super viewDidApper:animated] should be on the firstline within your viewDidAppear Method
  2. I'd move your code to viewWillAppear

Maybe this helps a bit.