2010-01-25 67 views
0

我的问题是我有一个自定义按钮和ImageView我添加了Image.I使这个imageView作为一个子视图的自定义按钮。当我在模拟器中运行它它工作正常,但是当我在Device中运行它时,它并没有在按钮中显示图像。与UIImageView自定义UIButton不能在设备上正常工作

我写的代码为:

在cellForRowtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MasterViewIdentifier"]; 
if (cell == nil) 
{ 

    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MasterViewIdentifier"] autorelease]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    UIView* elementView = [[UIView alloc] initWithFrame:CGRectMake(20,170,320,280)]; 
    elementView.tag = 0; 
    elementView.backgroundColor=[UIColor clearColor]; 
    [cell.contentView addSubview:elementView]; 
    [elementView release]; 

} 
UIView* elementView = [cell.contentView viewWithTag:0]; 
elementView.backgroundColor=[UIColor clearColor]; 
for(UIView* subView in elementView.subviews) 
{ 
    [subView removeFromSuperview]; 
} 
     if(indexPath.section == 8) 
    { 
      imageView.image = [UIImage imageNamed:@"yellow_Star.png"]; 
      MyCustomButton *button1 = [[MyCustomButton alloc]initWithRating:1]; 
    [button1 setFrame:CGRectMake(159, 15, 25, 20)]; 
    [button1 setShowsTouchWhenHighlighted:YES]; 
    [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
    [button1 addSubview:imageView]; 
    [elementView addSubview:button1]; 
    [button1 release]; 
    [imageView release]; 
     } 
return cell; 
} 

,并在我的buttonAction:

-(void)buttonAction:(MyCustomButton*)sender 
{ 
rating = [sender ratingValue]; 
event.eventRatings = rating; 
[tableView reloadData]; 

} 

和我MyCustomButton类: 我有一个方法

-(MyCustomButton*) initWithRating:(NSInteger)aRatingValue 
{ 
if (self = [super init]) 
{ 
    self.ratingValue = aRatingValue; 
} 
return self; 
} 

请帮助解决问题的人。

谢谢, Monish。

回答

0

您正在尝试加载名为“yellow_Star.png”的图像 - 检查它是否实际命名如此(使用相同的字符大小写)。 iPhone上的文件系统区分大小写,在Mac OS上不是 - 所以它通常会导致这样的问题,文件名是首先要看的。

编辑:您也可以尝试以检查图像出现在应用程序包 - 可它是从复制资源删除打造一步的机会,那就是你的形象必须是在“复制包资源”为您的构建目标构建步骤。如果它不存在,您可以将图像拖放到那里。

+0

是的,我给出了与大小写敏感相同的名称。尽管它不显示按钮中的图像。 – monish 2010-01-25 08:55:39

+0

您也可以尝试检查图像是否存在于应用程序包中 - 可能是从副本资源构建步骤中偶尔删除它 – Vladimir 2010-01-25 09:15:59

+0

实际上,图像存在于应用程序文件夹中,但它不存在于应用程序包中。将这些图像从应用程序文件夹中获取到XCode中的资源文件夹。 – monish 2010-01-25 09:36:58

相关问题