不兼容的指针类型发送&#NSString *'参数类型' UIImage *'

时间:2014-06-04 00:15:06

标签: ios objective-c uiimage

我试图以图片形式提出一个问题并且它无法正常工作,我知道如果问题出现在文本中则会是这样的

QusetionText.text=[NSString stringWithFormat@:"Who won World cup in 2006?"];

但我怎么用图片形式呢?

以下是代码:

-(void) ACat{
switch (QuestionSelected) {
    case 0:
        image = [UIImage imageNamed:@"question1.jpg"];
        [UIImageView setImage: image];    //ERROR HERE
        [Answer1 setTitle:@"GTA" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"COD" forState:UIControlStateNormal];
        [Answer4 setTitle:@"VatchDog" forState:UIControlStateNormal];
        Answer1Correct = YES;

        break;
    case 1:
        UIImage *image = [UIImage imageNamed:@"question2.png"];
        UIImageView.image = image;    //ERROR HERE
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"FIFA" forState:UIControlStateNormal];
        Answer2Correct = YES;

        break;

    case 2:
        UIImage *image = [UIImage imageNamed:@"question3.jpg"];
        UIImageView.image = image;    //ERROR HERE
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"FIFA" forState:UIControlStateNormal];
        Answer4Correct = YES;

        break;

    case 3:
        UIImage *image = [UIImage imageNamed:@"question4.jpeg"];
       UIImageView.image = image;    //ERROR HERE
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"Vatchdog" forState:UIControlStateNormal];
        Answer4Correct = YES;

        break;
    default:
        break;
    }
}

.h文件

#import <UIKit/UIKit.h>

int CategoryLoaded;
int QuestionSelected;
BOOL Answer1Correct;
BOOL Answer2Correct;
BOOL Answer3Correct;
BOOL Answer4Correct;


@interface contentViewController : UIViewController
{
IBOutlet UILabel *lcat;

IBOutlet UIImageView *image;

IBOutlet UIButton *Answer1;
IBOutlet UIButton *Answer2;
IBOutlet UIButton *Answer3;
IBOutlet UIButton *Answer4;
  }

-IBAction Answer1:(id)sender;
-IBAction Answer2:(id)sender;
-IBAction Answer3:(id)sender;
-IBAction Answer4:(id)sender;
-(void) ACat;
-(void) Rpg;


 @end 

1 个答案:

答案 0 :(得分:0)

这应该有效:

-(void) ACat{
switch (QuestionSelected) {
    case 0:
        image.image = [UIImage imageNamed:@"question1.jpg"];
        [Answer1 setTitle:@"GTA" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"COD" forState:UIControlStateNormal];
        [Answer4 setTitle:@"VatchDog" forState:UIControlStateNormal];
        Answer1Correct = YES;
        break;
    case 1:
        image.image = [UIImage imageNamed:@"question2.png"];
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"FIFA" forState:UIControlStateNormal];
        Answer2Correct = YES;
        break;

    case 2:
        image.image = [UIImage imageNamed:@"question3.jpg"];
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"FIFA" forState:UIControlStateNormal];
        Answer3Correct = YES;
        break;

    case 3:
        image.image = [UIImage imageNamed:@"question4.jpeg"];
        [Answer1 setTitle:@"LOL" forState:UIControlStateNormal];
        [Answer2 setTitle:@"Minecraft" forState:UIControlStateNormal];
        [Answer3 setTitle:@"DOTA" forState:UIControlStateNormal];
        [Answer4 setTitle:@"Vatchdog" forState:UIControlStateNormal];
        Answer4Correct = YES;
        break;
    }
}

您试图将UIImage分配给类型为image的{​​{1}}实例变量,然后尝试在UIImageView类本身上调用setImage: ,而不是类的实例。