2016-09-03 18 views
1

私はカスタムセルクラスでテーブルビューを持っています。uivutton背景画像が変更されていません。

セル内には5つのuibuttonがあり、そのカスタムクラスではすべてのコンセントを作成しており、このようなタップイベントを処理する機能は1つだけです。私は、ボタンをタップしているチェックしています、と私はブレークポイントを使用して、それをチェックしたとして、それが正常に動作しているタグのプロパティを使用して

- (IBAction)starClicked:(id)sender { 
UIButton *btn = (UIButton*)sender; 

switch (btn.tag){ 
    case 501: 
     self.starOne = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.starOne setBackgroundImage:[UIImage imageNamed:@"day-time-temp-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected]; 
     [self.starOne setTitle:@"23" forState:UIControlStateNormal]; 
     [self.starOne setNeedsLayout]; 
     self.starTwo = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.starTwo setBackgroundImage:[UIImage imageNamed:@"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected]; 
     self.starThree = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.starThree setBackgroundImage:[UIImage imageNamed:@"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected]; 
     self.starFour = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.starFour setBackgroundImage:[UIImage imageNamed:@"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected]; 
     self.starFive = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [self.starFive setBackgroundImage:[UIImage imageNamed:@"opening-time-icon.png"] forState:UIControlStateNormal|UIControlStateHighlighted|UIControlStateSelected]; 
     break; 
    ... 

} 
} 

。最初のボタンを押すと、最初のボタンの画像を変更したいと思います。 2番目のボタンでは、1番目と2番目のボタンの画像を変更したいと思います。これは評価コントロールのようなものです。スターのイメージを強調してスターイメージを変えたい。

ですが、コードが機能しません。私はsetNeedLayoutも設定しようとしました。しかし、イメージは変化していません。

編集

これは、行機能のための私のセルです。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
QuestionsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"questCell"]; 
if(cell == nil){ 
    cell = [[QuestionsCell alloc] init]; 
} 
[cell customizeCellWithQuestions:[self.questionList objectAtIndex:indexPath.row] textSize:1 index:indexPath.row]; 
return cell; 
} 

これは私のQuestionCellClass内の私のcustomizeCellWithQuestions機能です。

-(void)customizeCellWithQuestions:(Question *)question textSize:(float)textSize index:(NSUInteger)index{ 
[self.questionTitleTv setText:[question.question capitalizedString]]; 
[self.questionIndexLbl setText:[NSString stringWithFormat:@"%lu",(unsigned long)index+1]]; 
self.backgroundColor = [UIColor clearColor]; 
self.contentView.backgroundColor = [UIColor colorWithRed: 213.0/255.0 green: 213.0/255.0 blue: 213.0/255.0 alpha: 0.0]; 
} 
+0

あなたはより多くのコードを表示する必要は動作しませんOR演算子を使用して

、どのようにセットアップカスタムtableviewcellクラスとあなただけの星の評価のようにしたい – Shubhank

+0

何ですか? – Yawar

+0

私の質問を製作中ごcellForRow方法OK –

答えて

1

イメージを1つの状態に個別に設定する必要があります。

[self.starOne setBackgroundImage:[UIImage imageNamed:@"day-time-temp-icon.png"] forState:UIControlStateNormal];