views:

222

answers:

1

I have an app that is a list of tasks, like a to do list. The user configures the tasks and that goes to the SQLite db. The list is displayed in a tableview.

The SQL table in question consists of a taskid int, groupname varchar, taskname varchar, lastcompleted datetime, nextdue datetime, weighting integer.

I currently have it working by creating an array from each column in the SQL table. In the tableView:cellForRowAtIndexPath: method, I create the controls for each task by binding their values to the array for each column.

I want to add configurable task groups that should display as the section titles. I got the task groups to display as the section headers. My problem is that all the task rows are repeated in each group under each header.

How do I get the correct rows to show up only under the correct section?

I'm really new to development period and took on a hobby of trying to teach myself how to develop iphone apps. So, pretty please, be a little more detailed than you normally would with a professional developer. :)

A: 

Your problem is that your data model (in this case your arrays) don't reflect the sections. Right now, your are returning every row in the entire data model for each section.

The NSIndexPath passed to tableView:cellForRowAtIndexPath: has a section and row property. To return the proper rows for each section, you have to check the indexPath.section attribute to see which logical section the logical row belongs to before you populate the cell.

Edit:

You need something like this:

switch (indexPath.section) {
    case 0:
        // return row at indexPath.row for this section
        break;
    case 1:
        // return row at indexPath.row for this section
        break;

    default:
        break;
}
TechZen
I gave you a check for the answer. I'm going to try again and be a little more clear this time. I will include code.
Rank Beginner
The new question is "iPhone: Repeating Rows in Each Section of Grouped UITableview". You have already helped plenty so you don't have to spend any more time answering. Someone gave me some friendly feedback on question creation ;), so I have supplied the new question, hopefully a little more clearly. I should get better response on this. Thank you for your help with this!
Rank Beginner
3 days later, no one has attempted my newly formatted question. I think you hit the nail on the head, with the data model not representing the sections. Say for instance, you had an indexed table with sections based on the first letter of the row value. Would you have to do 26 separate queries in order to get your data model to represent the sections by alphabet? What if you don't know the number and associations of sections to rows until run time?
Rank Beginner
I didn't catch that you had posted an entirely new question. The normal practice is to edit the existing question in order to prevent duplication.
TechZen