2014-04-07 3 views
-1

넘어 인덱스 2 : 난 내가 추출하고이 LeavemanagementViewController.mjQuery과 경계 종료 응용 프로그램 'NSRangeException'- [__ NSArrayM objectAtIndex :] : 다음과 같은 코드에 문제가 경계 [0 .. 1] '

에게 있습니다 및 서버에서 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); 

} 
} 

제발 나를 도와주세요.

답변

0

StudentClass *student = (StudentClass *) [arrayitems objectAtIndex:tag-1]; 
+0

위의 코드를 추가하면 0 indexpath는 indexpath 1 값의 값을 표시합니다. –

+0

Button2.tag의 가치가 무엇인지 말해 주시겠습니까? –

+0

나는 tablecell에 버튼을 추가했습니다. // 버튼을 만들어 셀에 추가합니다. Reject button UIButton * button2 = [UIButton buttonWithType : UIButtonTypeRoundedRect]; button2.tag = indexPath.row; [button2 addTarget : 자기 동작 : @selector (RejectActionPressed :) forControlEvents : UIControlEventTouchDown]; button2.frame = CGRectMake (720.0f, 85.0f, 100.0f, 25.0f); [cell addSubview : button2]; –

0

그것은 경계 문제 중 일반적인 배열과 같이하십시오.

당신이 두 가지 요소의 배열을 가지고하고 그냥 배열을 인쇄

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

아래 한 Statment에 존재하지 않는 세 번째 요소를 참조하려고하면 오류

의 더 나은 이해를해야합니다
NSLog(@"Array =%@",arrayitems); //to debug 
+0

배열 수는 2 시간이고 배열 값을 가져 오는 중입니다. indexpath - (void) callRejectWebservice :이 조건의 (int) 태그 –

+0

배열 수 2는 "배열은 두 요소 배열 [0], 배열 [ 1]". 존재하지 않는 배열 [2]을 (를) 참조하고 있습니다. 그래서주는 오류입니다. – Dili

+0

귀하의 의견에 위의 코드를 지적 해주십시오. 그래서 어디에서 실수를하고 있는지 알려주세요 –