2016-11-08 188 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]; 

} 
    } 

遇到以下问题。请帮我解决一下这个。 TIA- [__ NSArrayI objectAtIndex:]:index 1 beyond bounds [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

看到这个http://stackoverflow.com/questions/12641051/ios-error- nsarrayi-objectatindex-index-1-beyond-bounds-0-0 –

+0

首先打印'jsonArr'以查看它是否为零或没有数据 – Tj3n

回答

0
NSMutableArray *jsonArr; 

ü需要添加

jsonArr = [NSMutableArray alloc] init]; 

送花儿给人初始化

0

检查这一点,

@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

在你- (void)jsonData:(NSDictionary *)jsonDict,更改:

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

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

现在改变:

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 
} 
相关问题