Iphone 如何在单击时查看上一个数组值
这里我用这段代码查看数组中的下一个值Iphone 如何在单击时查看上一个数组值,iphone,ios,uibutton,nsmutablearray,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:[arsoun
-(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++;
}
如何通过单击其他按钮查看上一个数组值?请帮助我解决..-(iAction)changeprov
-(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--;
}
{
静态int j=弧计数;
if(j<0)
{
j=弧计数;
}
lb1.text=[NSString stringWithFormat:[artext objectAtIndex:j]];
imager.image=[arimage objectAtIndex:j];
aplayer=[[AVAudioPlayer alloc]initWithData:[arsound objectAtIndex:j]错误:nil];
j--;
}
-(iAction)更改下一个或上一个:(id)发件人
{
静态int j=0;
如果(发送方==btnNext)
j++;
否则如果(发送方==btnPrev)
j--;
如果(j>=arcount)
{
j=0;
}
else如果(j<0)
{
j=弧计数-1;
}
lb1.text=[NSString stringWithFormat:[artext objectAtIndex:j]];
imager.image=[arimage objectAtIndex:j];
aplayer=[[AVAudioPlayer alloc]initWithData:[arsound objectAtIndex:j]错误:nil];
}
将两个按钮链接到同一个操作。回答得好,您还可以使用IB中按钮的tag属性,并使用这些属性来区分按钮(如果您真的不需要将它们声明为出口)。
-(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];
}