簡體   English   中英

將圖像添加到UIButton時出現問題。

[英]Issue in adding image to the 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的模擬器中構建應用程序時,通過顯示星形圖像可以正常工作。 我porblem是,當我在3.1.2 OS設備構建其圖像不displaying.I檢查代碼casesensitivity在文件名及其GUD但我不是gettig的圖像顯示。

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

謝謝Monish Kumar。

嘗試以下操作:-從iPhone中刪除您的應用程序-從構建菜單中清除所有標簽-將圖像復制到另一個目錄中-從項目中刪除圖像(刪除時單擊“也移至廢紙“”)-再次添加圖像-構建並運行

希望它能工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM