2012-10-18 14 views
0

在這裏,我用這個代碼在陣列中查看下一個值,如何查看以前的數組值上點擊

-(IBAction)changenext 
{ 
static int j = 0; 
if (j >arcount) 
{ 
    j = 0; 
} 
lb1.text=[NSString stringWithFormat:[artext objectAtIndex:j]]; 
imager.image=[arimage objectAtIndex:j]; 
aplayer=[[AVAudioPlayer alloc]initWithData:[arsound objectAtIndex:j] error:nil]; 

j++; 
} 

如何查看其他按鈕前一陣值單擊?請幫我解決。 。

回答

2
-(IBAction)change_next_or_prev:(id)sender 
{ 
static int j = 0; 
if(sender == btnNext) 
    j++; 
else if(sender == btnPrev) 
    j--; 
if (j >= arcount) 
{ 
    j = 0; 
} 
else if(j < 0) 
{ 
    j = arcount - 1; 
} 
lb1.text=[NSString stringWithFormat:[artext objectAtIndex:j]]; 
imager.image=[arimage objectAtIndex:j]; 
aplayer=[[AVAudioPlayer alloc]initWithData:[arsound objectAtIndex:j] error:nil]; 
} 

鏈接兩個按鈕,同樣的動作。

+0

itw工作,謝謝隊友:) – iosdev

+1

好的答案,你也可以使用IB中按鈕的標籤屬性,並使用這些按鈕來區分按鈕,如果你不需要將它們聲明爲插座。 –

0
-(IBAction)changeprev 
{ 
static int j = arcount; 
if (j < 0) 
{ 
    j = arcount; 
} 
lb1.text=[NSString stringWithFormat:[artext objectAtIndex:j]]; 
imager.image=[arimage objectAtIndex:j]; 
aplayer=[[AVAudioPlayer alloc]initWithData:[arsound objectAtIndex:j] error:nil]; 

j--; 
}