Tal Zamirly
Tal Zamirly

Reputation: 117

Basic IOS database application with SQLite3

So I am designing a simple application to practice my iOS development skills, and basically I am making a simple database application which contains different types of fruits and vegetables. I managed to read the whole database into my application and display it on a TableView, which is what I wanted. However, what I am seeing at the moment is all the fruit and vegetables together on the main page, and there are about a thousand of them. I would like to group the columns and move to the next table view, so for example if I press the Fruit table row, I will go on to a new TableView that will display ALL (and only) fruit, same goes for vegetables etc. I know I am meant to use GROUP BY, which group all the unique food types (e.g. fruit, vegetables, dairy), but not quite sure how to use it. Any help or advice would be highly appreciated.

Upvotes: 0

Views: 57

Answers (1)

Prajeet Shrestha
Prajeet Shrestha

Reputation: 8108

Ok this may be what you want:

First of Declare the dataarray:

NSMutableArray *datasource;

datasource=[[NSMutableArray alloc]initWithObjects:@"Fruits",@"Vegetables", nil];

Set the number of rows in table:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return [datasource count];
}

Input data to the cells:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycell" forIndexPath:indexPath];
    cell.textLabel.text=[datasource objectAtIndex:indexPath.row];

    // Configure the cell...

    return cell;
}

What you really need to do is here in prepare segue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DestinationVC *destVC = segue.destinationViewController;
    UITableViewCell *cell=[myTable cellForRowAtIndexPath:path];
    destVC.selectedFoodType=cell.textLabel.text;
    //This will pass what type of food you selected and pass it to the second tableview. Then there you can build the logic to populate table cells according to selected food type


}

Note: Connect the segue from cell to another view controller through storyboard. I am sure u know how :)

Upvotes: 1

Related Questions