开发者

iPhone: Same Rows Repeated in Each Section of Grouped UITableview

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 shoul开发者_C百科d 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. :)


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜