Ios -[u NSArrayI objectAtIndex:]:索引1超出范围[0..0]';
我有以下问题。请帮我做这个。短暂性脑缺血发作Ios -[u NSArrayI objectAtIndex:]:索引1超出范围[0..0]';,ios,objective-c,iphone,xcode,slidingmenu,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 setConte
@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];
}
}
你需要补充吗
NSMutableArray *jsonArr;
始终初始化检查此项
jsonArr = [NSMutableArray alloc] init];
在您的-(void)jsonData:(NSDictionary*)jsonDict
中,更改:
@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];
}
}
到
现在改变:
jsonArr = [[NSMutableArray alloc] initWithArray:[jsonDict objectForKey:@"DataTable"]];
致:
首先查看此打印
jsonArr
,查看其是否为零或没有数据
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
}