0

I create a message when a process starts (BOOL YES) and I am trying to make it go away when it ends (BOOL NO), debugging shows me stepping through the whole function both in the beginning and end, however the message is still there.

Where am I going wrong? Thank you in advance

-(void) loadStillLoadingMessage:(BOOL)yesNo{
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
UILabel *loading = [[[UILabel alloc]initWithFrame:CGRectMake((screenWidth/2)-75,(screenHeight)-140,300,40)]autorelease];

loading.text = @"still loading";
loading.backgroundColor = [UIColor clearColor];
loading.textColor = [UIColor blueColor];
loadingLabel = loading;
[self.view addSubview:loadingLabel];
[loadingLabel setHidden:YES];
if (yesNo == YES) {
    [loadingLabel setHidden:NO];
}else if (yesNo ==NO){
    [loadingLabel setHidden:YES];
}

}

4

2 回答 2

1

每当调用此方法UIView时,它都会创建一个。因此,UIView您第一次创建并显示与UIView您第二次创建、显示然后隐藏是不同的。您需要查看实例变量(在头文件中声明变量)。

于 2012-11-26T02:05:40.447 回答
1

您遇到的问题是您没有从 self.view 中删除旧的加载。

-(void) loadStillLoadingMessage:(BOOL)yesNo{
    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenWidth = screenSize.width;
    CGFloat screenHeight = screenSize.height;
    UILabel *loading = [[[UILabel alloc]initWithFrame:CGRectMake((screenWidth/2)-75,    (screenHeight)-140,300,40)]autorelease];

    loading.text = @"still loading";
    loading.backgroundColor = [UIColor clearColor];
    loading.textColor = [UIColor blueColor];
    loadingLabel = loading;

    //removing the previous label from the self.view if exist
    loadingLabel.tag = 999;
    [[self.view viewWithTag:999] removeFromSuperview];

    [self.view addSubview:loadingLabel];
    [loadingLabel setHidden:YES];
    if (yesNo == YES) {
         [loadingLabel setHidden:NO];
    }else if (yesNo ==NO){
      [loadingLabel setHidden:YES];
    }

}

于 2012-11-26T02:08:33.317 回答