2010-02-01 63 views
0

我在應用程序中遇到了另一個問題,我正在浪費這麼多時間。 請問任何人都可以幫助解決這個問題。將圖像添加到UIButton時出現問題。

其實我有一個事件,我應該給予評分該事件爲我寫的代碼爲:

在的cellForRowAtIndexPath ......我有代碼:

(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MasterViewIdentifier"]; 
    //UITableViewCell *cell = nil; 
    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) 
    { 
     UIImage *whiteImg = [UIImage imageNamed:@"white_star.png"] ; 
     UIImage *yellowImg = [UIImage imageNamed:@"yellow_Star.png"] ; 
     UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(159, 15, 25, 20)]; 
     [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     button1.tag = 1; 
     UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(185, 15, 25, 20)]; 
     [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     button2.tag = 2; 
     UIButton *button3 = [[UIButton alloc]initWithFrame:CGRectMake(211, 15, 25, 20)]; 
     [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     button3.tag = 3; 
     UIButton *button4 = [[UIButton alloc]initWithFrame:CGRectMake(237, 15, 25, 20)]; 
     [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     button4.tag = 4; 
     UIButton *button5 = [[UIButton alloc]initWithFrame:CGRectMake(263, 15, 25, 20)]; 
     [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     button5.tag = 5; 
     if(event.eventRatings == 1) 
     { 

     [button1 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 

     } 
     else if(event.eventRatings == 2) 
     { 
     [button1 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];  
     } 
     else if(event.eventRatings == 3) 
     { 
     [button1 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:whiteImg forState:UIControlStateNormal];   
     } 
     else if(event.eventRatings == 4) 
     { 

     [button1 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 

     } 
     else if(event.eventRatings == 5) 
     { 
     [button1 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:yellowImg forState:UIControlStateNormal]; 
     } 
     else 
     { 
     [button1 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button2 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button3 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button4 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     [button5 setBackgroundImage:whiteImg forState:UIControlStateNormal]; 
     } 

     [elementView addSubview:button1]; 
     [button1 release]; 
     [elementView addSubview:button2]; 
     [button2 release]; 
     [elementView addSubview:button3]; 
     [button3 release]; 
     [elementView addSubview:button4]; 
     [button4 release]; 
     [elementView addSubview:button5]; 
     [button5 release]; 

     if(isRightButton == YES) 
     { 
     button1.enabled = NO; 
     button2.enabled = NO; 
     button3.enabled = NO; 
     button4.enabled = NO; 
     button5.enabled = NO;  
     } 
     else if(isRightButton == NO) 
     { 
     button1.enabled = YES; 
     button2.enabled = YES; 
     button3.enabled = YES; 
     button4.enabled = YES; 
     button5.enabled = YES;  
     } 


     [elementView addSubview:ratingsTitleLabel]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
return cell; 
} 

And the action of the button is written as: 

    -(void)buttonAction:(id)sender 
    { 
    rating = [sender tag]; 
    printf("\n Ratig Value inside Button Action~~~~~~~~~~~~~~~~%d",rating); 
    event.eventRatings = rating; 
    [tableView reloadData];  
    } 

當我在3.1.2 OS的模擬器中構建應用程序時,它通過顯示星形圖像很好地工作。 當我在3.1.2 O.S設備中創建它時,我的圖標是不顯示的。我在文件名和它的gud中檢查了casesensitivity的代碼,但是Im沒有讓圖像顯示出來。

夥計們幫我解決這個問題。

謝謝, Monish Kumar。

+0

你好傢伙......幫我解決這個問題。 – monish 2010-02-01 09:38:30

+0

圖像加載是否正確?檢查調試,如果你的UIImage實例不是零。嘗試檢查應用程序包中是否缺少圖像。 – Vladimir 2010-02-01 09:48:43

+0

是的圖像加載和UIImage insatnce不是nil.Also圖像出現在應用程序捆綁。 – monish 2010-02-01 10:31:54

回答

0

試試這個: - 從iPhone 刪除您的應用程序 - 明確從生成菜單 所有tagets - 在另一個目錄 複製你的圖像 - 從項目中刪除圖像(當刪除單擊「也移到回收站」) - 添加你的圖像再次 - 建立和去

希望它的工作。

+0

嗨Dreiu我嘗試了所有的事情,因爲你建議...仍然沒有come.I donno y它發生了這樣的事情,你可以建議我任何其他的想法? – monish 2010-02-01 13:00:55

+0

您是否嘗試過使用其他圖像? – 2010-02-01 13:15:00

+0

是的,我嘗試使用其他圖像在Device中正常工作。 – monish 2010-02-01 13:30:57

相關問題