我在进程启动时创建一条消息(BOOL YES)并且我试图让它在结束时消失(BOOL NO),调试显示我在开始和结束时单步执行整个功能,但是消息还在那里。
我哪里错了?提前谢谢
-(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];
}
}
答案 0 :(得分:1)
此方法在调用时创建UIView
。因此,您第一次创建和显示的UIView
与您创建的UIView
不同,第二次显示然后隐藏。您需要查看实例变量(在头文件中声明变量)。
答案 1 :(得分: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];
}
}