2012-01-27 42 views
0

值我有2个视图控制器。在第一个我在tableview中选择一个分类。在接下来的观点我想表明categorie我在前面tableview中选定范围内的所有产品。我用一个php文件从我的数据库中获取数据。如何从以前的tableview

这是我firstViewController.m的“catVal”是我想给我下的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]; 


} 

在我的第二个视图控制器我有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); 

} 

我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 

当我尝试这种 '[productVC fillArrayProducts:catVal]。'在我的tableview DID选择行功能它不起作用。有人有想法吗?

回答

0

ü呼吁乌尔第二种观点*唯冠,然后你在productVC调用fillArrayProducts代替。改变

KiesProduct *proView = [[KiesProduct alloc] initWithNibName:@"KiesProduct" bundle:nil]; 
NSDictionary *info = [json objectAtIndex:indexPath.row]; 
NSString *catVal = [info objectForKey:@"Cat_naam"]; 
[proView fillArrayProducts:catVal]; 
[self.navigationController pushViewController:proView animated:YES]; 
+0

好现在的工作!谢谢 ! – steaphann 2012-01-27 14:54:53