- [__ NSArrayI objectAtIndex:]:索引1超出边界[0 .. 0]'

时间:2016-11-08 10:31:00

标签: ios objective-c iphone xcode slidingmenu

@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];

    gender=@"0";
    seekingGender=@"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 *error=@"Somthing Went Wrong";

    [SVProgressHUD showErrorWithStatus:error];

}
  }

得到以下问题。请帮我解决一下这个。 TIA

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

3 个答案:

答案 0 :(得分:0)

NSMutableArray *jsonArr;

你需要添加

jsonArr = [NSMutableArray alloc] init];

Alway初始化

答案 1 :(得分: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];

    gender=@"0";
    seekingGender=@"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 *error=@"Somthing Went Wrong";

    [SVProgressHUD showErrorWithStatus:error];

}
  }

答案 2 :(得分:0)

delimiter // CREATE TRIGGER `C_edit` AFTER UPDATE ON `client` FOR EACH ROW BEGIN IF OLD.name != NEW.name THEN INSERT INTO `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) VALUES (OLD.id_user_edit, 'client', 'name', OLD.id_client, '4', OLD.name, NEW.name); END IF; IF OLD.name_sql != NEW.name_sql THEN INSERT INTO `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) VALUES (OLD.id_user_edit, 'client', 'name_sql', OLD.id_client, '4', OLD.name_sql, NEW.name_sql); END IF; END// delimiter ; 中,更改:

- (void)jsonData:(NSDictionary *)jsonDict

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

现在改变:

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

为:

dict=[jsonArr objectAtIndex:0];