2013-01-12 48 views
-1

我正在嘗試加載與用戶選擇的表視圖行/單元對應的圖像和標籤。該代碼出現在我的DetailViewController實現文件中,如下所示:聲明需要用switch語句表達整型(int無效)錯誤

- (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

「characterNumber」的聲明是什麼?這是唯一重要的事情。 –

回答

1

使數據類型characterNumber爲int。

+0

它不一定是'int'。它可以是任何整型(char,int,short,long,NSInteger,*等) – rmaddy

+0

我知道。我問他,因爲他已經用0,1,2作爲病例陳述。 – Apurv

+0

@property int * characterNumber; – pjv