Iphone 带有UIImageView的自定义UIButton不';我不能在设备上正常工作
我的问题是我有一个自定义按钮和ImageView,我在其中添加了图像。我将此ImageView作为子视图添加到自定义按钮。当我在模拟器中运行它时,它工作正常,但当我在设备中运行它时,它没有在按钮中显示图像 我将代码编写为: 在cellForRowtIndexPath中Iphone 带有UIImageView的自定义UIButton不';我不能在设备上正常工作,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我的问题是我有一个自定义按钮和ImageView,我在其中添加了图像。我将此ImageView作为子视图添加到自定义按钮。当我在模拟器中运行它时,它工作正常,但当我在设备中运行它时,它没有在按钮中显示图像 我将代码编写为: 在cellForRowtIndexPath中 - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell
- (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;
}
在我的按钮上:
-(void)buttonAction:(MyCustomButton*)sender
{
rating = [sender ratingValue];
event.eventRatings = rating;
[tableView reloadData];
}
我的自定义按钮类:
我有一个方法
-(MyCustomButton*) initWithRating:(NSInteger)aRatingValue
{
if (self = [super init])
{
self.ratingValue = aRatingValue;
}
return self;
}
请帮我解决这个问题
谢谢,,
莫尼什。您正在尝试加载名为“yellow_Star.png”的图像-检查它是否实际命名为“yellow_Star.png”(大小写相同)。iPhone上的文件系统区分大小写,而Mac OS上的文件系统则不区分大小写——因此,它经常会导致此类问题,文件名是首先要看的
编辑:您还可以尝试检查该映像是否存在于应用程序包中-可能它是偶然从复制资源生成中删除的,也就是说,您的映像必须位于生成目标的“复制包资源”生成步骤中。如果没有,您可以将图像拖放到那里。是的,我给了相同的名称,仅区分大小写。即使它没有在按钮中显示图像。您也可以尝试检查该图像是否存在于应用程序包中-可能是从复制资源生成中一步一步地删除的,实际上图像存在于中应用程序文件夹在应用程序包中不存在。我将这些图像从应用程序文件夹中获取到XCode中的Resources文件夹中。