2016-11-08 2 views
-3
@implementation BasicProfileView 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    [self.scrollView addSubview:_basicProfileView]; 
    [_scrollView setContentSize:self.basicProfileView.frame.size]; 

    [email protected]"0"; 
    [email protected]"0"; 
    _basicProfileView.backgroundColor=[UIColor clearColor]; 

    } 

- (IBAction)btnContinue:(id)sender { 

[self callSignupProfileService]; 
    } 

-(void)callSignupProfileService 
{ 
NSString * post = [[NSString alloc]initWithFormat:@"userId=%@&cell_phone=%@&work_phone=%@&gender=%@&seekgender=%@&address=%@&country=%@&state=%@&city=%@&motherTongue=%@&zipcode=%@",UserId,_txtCellPhone.text,_txtWorkPhone.text,gender,seekingGender,_txtAdress.text,_WSConstCountryID,_WSConstStateID,_WSConstCityID,_WSConstLanguageID,_txtZipcode.text]; 
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"URL"]]; 
    RBConnect = [[RBConnection alloc]init]; 
    RBConnect.delegate = self; 
    [RBConnect postRequestForUrl:url postBody:post]; 
} 

- (void)jsonData:(NSDictionary *)jsonDict 
{ 
    [SVProgressHUD dismiss]; 

    NSMutableArray *jsonArr; 
    NSMutableDictionary *userDict,*dict; 

    jsonArr=[jsonDict objectForKey:@"DataTable"]; 
dict=[jsonArr objectAtIndex:0]; 
    userDict=[dict objectForKey:@"ABSUserProfile"]; 



if (userDict.count>2) { 


    self.navigationController.navigationBarHidden=YES; 

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 

    ECSlidingViewController *newView = [mainStoryboard instantiateViewControllerWithIdentifier:@"slidingmenu"]; 
    [self.navigationController pushViewController:newView animated:YES]; 



} 

else 
{ 

    NSString *[email protected]"Somthing Went Wrong"; 

    [SVProgressHUD showErrorWithStatus:error]; 

} 
    } 

Vous avez le problème suivant. S'il vous plait, j'ai besoin de votre aide avec ceci. TIA- [__ NSArrayI objectAtIndex:]: index 1 au-delà des limites [0 .. 0] '

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 
*** First throw call stack: 
(0x246af91b 0x23e4ae17 0x245c1987 0x6b4d3 0x28c430e5 0x28c42e87 0xb0ecf 0xb099d 0xaf5d9 0xaf3ad 0xaf2d1 0x7fa23 0x28c62755 0x28de3b91 0x28c62755 0x28c626e1 0x28c4a6d3 0x28c4a7ff 0x28c62005 0x28c61c7f 0x28c5a68f 0x28c2b125 0x28c296d3 0x24671dff 0x246719ed 0x2466fd5b 0x245bf229 0x245bf015 0x25bafac9 0x28c93189 0xca8a9 0x24267873) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+1

voir ce http://stackoverflow.com/questions/12641051/ios-error- nsarrayi-objectatindex-index-1-beyond-bounds-0-0 –

+0

imprimer 'jsonArr' d'abord voir si c'est nul ou ne pas avoir de données – Tj3n

Répondre

0
NSMutableArray *jsonArr; 

U besoin d'ajouter

jsonArr = [NSMutableArray alloc] init]; 

initialisation Alway

0

vérifier,

@implementation BasicProfileView 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    jsonArr = [NSMutableArray new]; 
    [self.scrollView addSubview:_basicProfileView]; 
    [_scrollView setContentSize:self.basicProfileView.frame.size]; 

    [email protected]"0"; 
    [email protected]"0"; 
    _basicProfileView.backgroundColor=[UIColor clearColor]; 

    } 

- (IBAction)btnContinue:(id)sender { 

[self callSignupProfileService]; 
    } 

-(void)callSignupProfileService 
{ 
NSString * post = [[NSString alloc]initWithFormat:@"userId=%@&cell_phone=%@&work_phone=%@&gender=%@&seekgender=%@&address=%@&country=%@&state=%@&city=%@&motherTongue=%@&zipcode=%@",UserId,_txtCellPhone.text,_txtWorkPhone.text,gender,seekingGender,_txtAdress.text,_WSConstCountryID,_WSConstStateID,_WSConstCityID,_WSConstLanguageID,_txtZipcode.text]; 
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"URL"]]; 
    RBConnect = [[RBConnection alloc]init]; 
    RBConnect.delegate = self; 
    [RBConnect postRequestForUrl:url postBody:post]; 
} 

- (void)jsonData:(NSDictionary *)jsonDict 
{ 
    [SVProgressHUD dismiss]; 

    NSMutableArray *jsonArr; 
    NSMutableDictionary *userDict,*dict; 

    jsonArr=[jsonDict objectForKey:@"DataTable"]; 

    if (jsonArr != nil && [jsonArr count] > 0) { 

    dict=[jsonArr objectAtIndex:0]; 

    userDict=[dict objectForKey:@"ABSUserProfile"]; 

    if (userDict.count>2) { 
     self.navigationController.navigationBarHidden=YES; 
     UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 

     ECSlidingViewController *newView = [mainStoryboard instantiateViewControllerWithIdentifier:@"slidingmenu"]; 
     [self.navigationController pushViewController:newView animated:YES]; 
    } 

} 

else 
{ 

    NSString *[email protected]"Somthing Went Wrong"; 

    [SVProgressHUD showErrorWithStatus:error]; 

} 
    } 
0

Dans votre - (void)jsonData:(NSDictionary *)jsonDict, le changement:

jsonArr=[jsonDict objectForKey:@"DataTable"]; 

à

jsonArr = [[NSMutableArray alloc] initWithArray:[jsonDict objectForKey:@"DataTable"]]; 

changer maintenant:

dict=[jsonArr objectAtIndex:0]; 

à:

if([jsonArr count]>0){ 
    dict=[jsonArr objectAtIndex:0]; 
    //Do whatever you want, your jsonArr is valid as it has objects 
} 
else{ 
//Perform necessary action here as your jsonArr is empty 
}