My problem is I have a Custom button and ImageView to which I added the Image.I made this imageView to the custom button as a subview.when Im running it in simulator it workin fine,but when Im runnig it in Device it was not displaying the image in the button.
我的问题是我有一个自定义按钮和ImageView,我在其中添加了图像。我将这个imageView设为自定义按钮的子视图。当我在模拟器中运行时,它运行得很好,但是当我在设备中运行时,它并没有在按钮中显示图像。
I written the code as:
我将代码写成:
In cellForRowtIndexPath
在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;
}
and in my buttonAction:
在我buttonAction:
-(void)buttonAction:(MyCustomButton*)sender
{
rating = [sender ratingValue];
event.eventRatings = rating;
[tableView reloadData];
}
and i MyCustomButton class: i have a method as
我有一个方法a
-(MyCustomButton*) initWithRating:(NSInteger)aRatingValue
{
if (self = [super init])
{
self.ratingValue = aRatingValue;
}
return self;
}
pls help guys from dis problem.
请帮助那些有问题的人。
Thank you, Monish.
谢谢你,Monish。
1 个解决方案
#1
0
You're trying to load image named "yellow_Star.png" - check if it actually named so (with the same characters case). File system on iPhone is case sensitive and on Mac OS is not - so it is often causes such problems and file names is the first thing to look at.
您正在尝试加载名为“yellow_Star”的图像。-检查它是否真的命名为这样(使用相同的字符案例)。iPhone上的文件系统是区分大小写的,而Mac OS上的文件系统则不是——因此它经常会导致这样的问题,文件名是首先要考虑的。
Edit: You can also try to check if the image is present in the application bundle - may be it was removed from copy resources build step by chance, that is your image must be in a "Copy Bundle Resources" build step for your build target. If it is absent you can just drag and drop your image there.
编辑:您还可以尝试检查应用程序包中的图像是否存在——可能是由于复制资源构建步骤被删除,这是您的映像必须在“复制包资源”构建步骤中为您的构建目标构建步骤。如果没有,你可以拖放你的图像到那里。
#1
0
You're trying to load image named "yellow_Star.png" - check if it actually named so (with the same characters case). File system on iPhone is case sensitive and on Mac OS is not - so it is often causes such problems and file names is the first thing to look at.
您正在尝试加载名为“yellow_Star”的图像。-检查它是否真的命名为这样(使用相同的字符案例)。iPhone上的文件系统是区分大小写的,而Mac OS上的文件系统则不是——因此它经常会导致这样的问题,文件名是首先要考虑的。
Edit: You can also try to check if the image is present in the application bundle - may be it was removed from copy resources build step by chance, that is your image must be in a "Copy Bundle Resources" build step for your build target. If it is absent you can just drag and drop your image there.
编辑:您还可以尝试检查应用程序包中的图像是否存在——可能是由于复制资源构建步骤被删除,这是您的映像必须在“复制包资源”构建步骤中为您的构建目标构建步骤。如果没有,你可以拖放你的图像到那里。