2012-01-27 32 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

相關問題