如何在单击时查看以前的数组值

时间:2012-10-18 06:36:45

标签: iphone ios uibutton nsmutablearray

在这里,我使用此代码查看数组中的下一个值

-(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 个答案:

答案 0 :(得分: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];
}

将两个按钮链接到同一个动作。

答案 1 :(得分: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--;
}