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++;
}

如何通过其他按钮单击查看先前的数组值?请帮我解决..

4

2 回答 2

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];
}

将两个按钮链接到相同的操作。

于 2012-10-18T06:45:16.930 回答
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--;
}
于 2012-10-18T06:39:45.637 回答