i have a table VC in which i have pass static array of list and when we click the item in an array it open its view controller, Now i have written another view controller at index 9 but when i run the app it shows me error of * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 10 beyond bounds [0 .. 9]'. Indexing is fine but i don't know why it is coming. My code is,
NSString *success= [successDefaults valueForKey:@"Success"];
if ([success isEqual:@"Success"]) {
NSString *string1 = [successDefaults stringForKey:@"name"];
NSLog(@"Name is %@",string1);
LeftMenuData1=[[NSArray alloc]initWithObjects:string1,@"Home",@"Show Franchiser",@"AboutUs",@"Logout",@"Contact Us",@"Wanted",@"Terms&Conditions",@"Share App",@"View Properties",@"Chat", nil];
[self.tableView reloadData];
}else{
LeftMenuData1=[[NSArray alloc]initWithObjects:@"",@"Home",@"Show Franchiser",@"AboutUs",@"Login/Register",@"Contact Us",@"Wanted",@"Terms&Conditions",@"Share App",@"Chat",nil];
[self.tableView reloadData];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [LeftMenuData1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell.textLabel.text=[LeftMenuData1 objectAtIndex:indexPath.row];
cell.imageView.image=[UIImage imageNamed:[LeftMenuDataImages1 objectAtIndex:indexPath.row]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
float height = 40;
NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];
int currentLoginStatus = [str111 intValue];
if(currentLoginStatus == 0 && indexPath.row == 0)
height = 0;
return height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@",selectedCell.textLabel.text);
AppDelegate *app=(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
NSInteger row = indexPath.row;
NSString *str=[NSString stringWithFormat:@"%@",[LeftMenuData1 objectAtIndex:indexPath.row]];
NSLog(@"%@",str);
if (row == 0) {
NSString *str111=[NSString stringWithFormat:@"%@",[successDefaults valueForKey:@"currentUser"]];
int currentLoginStatus = [str111 intValue];
if(currentLoginStatus == 1)
{
UpViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Up"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
} else if(currentLoginStatus == 2)
{
UserProfileViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"profile"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}
}else if(row == 1){
HomePageViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 2){
FransFormViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"frans"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 3){
AboutUsViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"AboutUs"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 4){
NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
if ([[successDefaults valueForKey:@"Success"] isEqualToString:@"Success"]) {
[successDefaults setObject:@"NO" forKey:@"Success"];
[successDefaults setObject:@"0" forKey:@"currentUser"];
[successDefaults synchronize];
[successDefaults synchronize];
[app.drawer toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}else{
GeneralLoginViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"General"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}
}else if(row == 5){
ContactInfoViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactInfo"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 6){
WantedViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"WantedViewController"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 7){
Terms_ConditionViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Terms"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}else if (row == 8){
ShareViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"Share"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}
else if (row==9) {
TestChat *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Chat"];
[self.navigationController pushViewController:vc animated:YES];
}
else if (row == 10){
NSUserDefaults *successDefaults=[NSUserDefaults standardUserDefaults];
if ([[successDefaults valueForKey:@"Success"] isEqualToString:@"Success"]){
ViewPersonalTableViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewProps"];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:presales];
[app.drawer setCenterViewController:nav withCloseAnimation:true completion:nil];
}
}else{
}
}