I have 2 view controllers. In the first I select a categorie in a tableview. In the next view I want to show all the products within that categorie I selected in the previous tableview. I get the data from my database with a php file.
This is my firstViewController.m The ‘catVal’ is the value I wanna give to my next ViewController.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
KiesProduct *proView = [[KiesProduct alloc] initWithNibName:@"KiesProduct" bundle:nil];
[self.navigationController pushViewController:proView animated:YES];
NSDictionary *info = [json objectAtIndex:indexPath.row];
NSString *catVal = [info objectForKey:@"Cat_naam"];
[productVC fillArrayProducts:catVal];
}
In my second view controller I have the function fillArayProducts.
-(void) fillArrayProducts:(NSString *)cat{
NSLog(@"test");
NSMutableString *postString = [NSMutableString stringWithString:kGETProducts];
[postString appendString:[NSString stringWithFormat:@"?%@=%@",@"Pro_cat",cat]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request= [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:@"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:postString]];
NSError *error;
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
arrayProducts = [[NSMutableArray alloc] init];
for (int i=0; i<[json count]; i++) {
NSDictionary *info = [json objectAtIndex:i];
[arrayProducts addObject:[info objectForKey:@"Pro_naam"]];
}
NSLog(@"%@",arrayProducts);
}
my secondViewController.m
#import <UIKit/UIKit.h>
#define kGETProducts @"http://localhost/getProducts.php"
@interface KiesProduct : UITableViewController{
NSMutableArray *json;
NSMutableArray *arrayProducts;
NSURLConnection *postConnection;
}
-(IBAction)add:(id)sender;
-(void) fillArrayProducts:(NSString *)cat;
@end
When i try this ‘[productVC fillArrayProducts:catVal];’ in my tableview DID Select row function it doesn’t work. Anybody got an idea ?
u are calling ur second view *proView and then you are calling fillArrayProducts on productVC instead. change to