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。
是的,我给出了与大小写敏感相同的名称。尽管它不显示按钮中的图像。 – monish 2010-01-25 08:55:39
您也可以尝试检查图像是否存在于应用程序包中 - 可能是从副本资源构建步骤中偶尔删除它 – Vladimir 2010-01-25 09:15:59
实际上,图像存在于应用程序文件夹中,但它不存在于应用程序包中。将这些图像从应用程序文件夹中获取到XCode中的资源文件夹。 – monish 2010-01-25 09:36:58