views:

75

answers:

2

Hi,

I have a TableView who display the name of some Categories by executing this simple query

 
"select * from category" so my object contain id_category and name.

When I click on a row, a new tableView will display somes names inside thoses different categories.


"Select * from fiche_Category where id_category = ?"

My only problem is I don't know how to retrieve the id_category from every cell and insert it inside my ? on my second query.

I just want to be able to display the fiche_category from the category I choose.

Best Regards,

+1  A: 

In the

tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

method, you can find the index of the cell you clicked by using:

int index = [indexPath indexAtPosition:[indexPath length] - 1];

with this index you can go through the result you retrieved from your first sql statement and find the record you clicked and with that the id_category.

Vincent Osinga
thanks that will maybe help me for later.. but what is the -1 ??
ludo
if you have an array with length n then the index of the last element is n-1
Vincent Osinga
A: 

I find another solution, In my file ressource Manager I create a function to take a int as an argument:


- (void)getFichesCategory:(int)value { 
...
sqlite3_bind_int(getFichesCategoryStatement, 1,  value);
...
}

After that inside my View controller, I use the ViewWillAppear and I call my function where I retrieve the id_category from my 1st query [self.categories idModuleCategory] intValue] :


- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    self.title = self.categories.title;

    RessourceManager *appDelegate = [RessourceManager  sharedResources];
    [appDelegate getFichesCategory:[[self.categories idModuleCategory] intValue] ];
    [self.tableView reloadData];

}
ludo