2010-01-25 5 views
0

내 문제는 사용자 정의 단추 및 ImageView를 추가 한 ImageView입니다.이 imageView를 subview.when으로 만든이 imageView를 시뮬레이터에서 실행했습니다. 잘 작동하지만, Im 디바이스에서 실행하면 버튼에 이미지가 표시되지 않습니다.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; 
} 
로하는 방법

pls는 문제에서 남자를 도와줍니다.

감사합니다. Monish.

답변

0

"yellow_Star.png"라는 이미지를로드하려고합니다. 실제로 이름이 so (대문자와 같은 경우)인지 확인하십시오. iPhone의 파일 시스템은 대소 문자를 구별하며 Mac OS에서는 그렇지 않습니다. 따라서 종종 이러한 문제가 발생하고 파일 이름이 가장 먼저보아야합니다.

편집 : 또한 이미지가 응용 프로그램 번들에 있는지 확인할 수도 있습니다. 빌드 타겟을위한 빌드 단계. 결석 한 경우에는 이미지를 끌어다 놓을 수 있습니다.

+0

예 대/소문자를 구분하여 동일한 이름을 지정했습니다. 단추에 이미지가 표시되지 않았지만. – monish

+0

이미지가 응용 프로그램 번들에 있는지 확인할 수도 있습니다. 복사 리소스에서 이미지가 제거되었는지 확인하십시오. – Vladimir

+0

실제로 이미지는 응용 프로그램 번들에 없습니다. 해당 이미지를 응용 프로그램 폴더에서 XCode의 Resources 폴더로 가져옵니다. – monish

관련 문제