UIImageView.hidden = NO;但图像不可见?

时间:2011-09-07 13:25:58

标签: objective-c uiimageview properties

SomeImage 是全局声明的UIImageView *

-(void)InMethodCalledFromViewDidLoad
{
    SomeImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SomeImage.png"]];
SomeImage.frame = CGRectMake(0, 640, 1024,110);
[self.view addSubview:SomeImage];
    SomeImage.hidden = YES;
    [self OneMoreMethod];
}


-(void)OneMoreMethod{
SomeImage.hidden = NO;//image becomes visible

[self SecondMethod];
/*but now from this point onwards even if SomeImage.hidden changed to NO then only nummerical value of SomeImage.hidden changes but image itself stays hidden doesnt become visible at all */
 }


 -(void)SecondMethod

 {

int tmp = 0;
NSArray* PosAndSizeArrForCurrSlot = [[PosAndSizeArr objectAtIndex:SlotId] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]];
for(NSString* values in PosAndSizeArrForCurrSlot)
  PositionAndSize[tmp++]  = [values intValue];

}

我无法理解为什么即使在调用SecondMethod之后将hiiden属性设置为NO,SomeImage也不可见。

3 个答案:

答案 0 :(得分:1)

您尝试在哪种设备上显示图像?

SomeImage.frame = CGRectMake(0, 640, 1024,110);

很可能会尝试在设备的可见区域外显示imageview。 另外,您应该参考本指南:http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml

只有常量和类应以大写字母开头,变量和方法名称应始终以小写字母开头。

答案 1 :(得分:1)

这可能是一个“呃”答案,但似乎总是咬我的屁股,你的imageview是否连接到.xib?如果未设置插座,则不会收到更改。

答案 2 :(得分:0)

您可以在前端和末端放置一些NSLog,以便确保代码执行到您使图像可见的位置吗?

-(void)OneMoreMethod{
   //SomeImage.hidden = NO;//image becomes visible
   NSLog(@"before SecondMethod");    
   [self SecondMethod];
   NSLog(@"after SecondMethod");    
   SomeImage.hidden = NO;//image becomes visible
   NSLog(@"after hidden = No");
}

我猜的是[self SecondMethod]中有一些崩溃,然后永远不会到达SomeImage.hidden = NO;