-1

次のコードに問題があります: 私はこの LeavemanagementViewController.m を持っています

サーバーからxmlからデータを抽出してロードしています。要素の総数は配列によって異なります。

-(void)RejectActionPressed:(id)sender
{
if ([approve1role.text isEqualToString:datarole.text])
{
    UIButton *buttn2=(UIButton*)sender;
    NSLog(@"bttn.tag==%i",buttn2.tag);

    StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:buttn2.tag];
    NSLog(@"student name= %@ \n leavecode %@ \n joining dat=%@",student.employeeName,student.leavecode,student.joiningdate);

    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Alert" message:@" " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    alert1.tag = buttn2.tag;
    alert1.tag = kAlertViewTwo; CGRect frame = CGRectMake(14, 45, 255, 23);
    remarkstext = [[UITextField alloc] initWithFrame:frame];
    remarkstext.placeholder = @"Name";
    remarkstext.backgroundColor = [UIColor whiteColor];
    remarkstext.autocorrectionType = UITextAutocorrectionTypeDefault;
    remarkstext.keyboardType = UIKeyboardTypeAlphabet;
    remarkstext.returnKeyType = UIReturnKeyDone;
    remarkstext.clearButtonMode = UITextFieldViewModeWhileEditing; 
    [alert1 addSubview:remarkstext];
    [alert1 show];
 }
 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
     {
 if(alertView.tag == kAlertViewOne)
{
    if (buttonIndex==1)
       {
         NSLog(@"%@",remarkstext.text);
         remarksoutput.text = remarkstext.text;
         NSLog(@" The Alertview%@",remarksoutput.text);
           [self callWebservice:alertView.tag];
       }
     else if (buttonIndex==0)
      {
       NSLog(@"cancel");
      }
  }
if(alertView.tag == kAlertViewTwo)
{
    if (buttonIndex==1)
    {
        NSLog(@"%@",remarkstext.text);

        remarksoutput.text = remarkstext.text;
         NSLog(@" The Alertview%@",remarksoutput.text);
        [self callRejectWebservice:alertView.tag];
    }
    else if (buttonIndex==0)
    {
        NSLog(@"cancel");
   }
}
   }

  -(void)callRejectWebservice:(int)tag
    {
    if ([approve1role.text isEqualToString:datarole.text])
{
    StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:tag];  // Here is my error *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'           
    NSLog(@"student name= %@ \n leavecode %@ \n joining dat=%@",student.employeeName,student.leavecode,student.joiningdate);
}
if ([approve2role.text isEqualToString:datarole.text])
{

    StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:tag];
    NSLog(@"student name= %@ \n leavecode %@ \n joining dat=%@",student.employeeName,student.leavecode,student.joiningdate);

}
if ([approve3role.text isEqualToString:datarole.text])
{
    StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:tag];
    NSLog(@"student name= %@ \n leavecode %@ \n joining dat=%@",student.employeeName,student.leavecode,student.joiningdate);

}
 }

これから私を助けてください。

4

2 に答える 2

0

範囲外の問題の一般的な配列のように見えます。

あなたは2つの要素の配列を持っていて、以下のステートメントには存在しない3番目の要素を参照しようとしています

StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:buttn2.tag];

配列を印刷するだけで、エラーをよりよく理解できます

NSLog(@"Array =%@",arrayitems); //to debug
于 2014-04-07T10:49:33.573 に答える
0

これを試して

StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:tag-1];
于 2014-04-07T10:45:41.273 に答える