语句需要使用switch语句表达整数类型(int invalid)错误

时间:2013-01-12 05:20:21

标签: ios int switch-statement

我正在尝试加载与用户选择的表视图行/单元格对应的图像和标签。代码出现在我的DetailViewController实现文件中,如下所示:

- (void)viewDidLoad
{
[super viewDidLoad];

//Create a couple of UIImages
UIImage *jenImage = [UIImage imageNamed:@"102_2262.jpg"];
UIImage *jen2Image = [UIImage imageNamed:@"102_2288.jpg"];
UIImage *paigeImage = [UIImage imageNamed:@"102_2332.jpg"];
UIImage *parkerImage = [UIImage imageNamed:@"102_2379.jpg"];

//Switch UIImages and UILabel based on characterNumber
switch (characterNumber) {
    case 0:
        characterName.text = @"Casual Jen";
        characterPic.image = jenImage;
        self.title = @"Casual Jen";
        break;
    case 1:
        characterName.text = @"Dressed Up Jen";
        characterPic.image = jen2Image;
         self.title = @"Dressed Up Jen";
        break;
    case 2:
        characterName.text = @"Paige";
        characterPic.image = paigeImage;
        self.title = @"Paige";
        break;
    case 3:
        characterName.text = @"Parker";
        characterPic.image = parkerImage;
        self.title = @"Parker";
        break;
    default:
        characterName.text = @"Parker";
        characterPic.image = parkerImage;
        self.title = @"Parker";
        break;
    }
}

switch语句产生错误,如上所述。我在这里和其他地方寻找解决方案但没有成功。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

将数据类型characterNumber设为int。