views:

276

answers:

1

Hi guys,

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.

I written the code as:

In 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:

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

}

and i MyCustomButton class: i have a method as

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

pls help guys from dis problem.

Thank you, Monish.

A: 

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.

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.

Vladimir
Yes I had given the same name with Case sensitive only.Even though it was not displaying the image in button.
monish
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
Vladimir
Actually the Images are present in the application folder it was not present in the application bundle.and I get those images from the application folder to the Resources folder in the XCode.
monish
Ok Thank you very much for your help.Ill try it according to your advice.
monish