Question

Can someone please help me. Im very new at this and trying to seque to my detail screen, which works fine as long as i don't use sections. The files i try to grab in the detail are html files. (numbered 1 - 53). When is seque to detail without sections i simply use htmlFile = [artikelen objectAtIndex:[path row]] to seque;

When i use sections [path row] will be something like [0.1] instead of continues numbering.

I sure hope someone can help me solve and understand this problem.

Thanks.

Jaco

   [super viewDidLoad];
    artikelen = [[NSMutableArray alloc]initWithObjects:@"artikel1",@"artikel2",@"artikel3",@"artikel4",@"artikel5",@"artikel6",@"artikel7",@"artikel8",@"artikel9",@"artikel10",@"artikel11",@"artikel12",@"artikel13",@"artikel14",@"artikel15",@"artikel16",@"artikel17",@"artikel18",@"artikel19",@"artikel20",@"artikel21",@"artikel22",@"artikel23",@"artikel24",@"artikel25",@"artikel26",@"artikel27",@"artikel28",@"artikel29",@"artikel30",@"artikel31",@"artikel32",@"artikel33",@"artikel34",@"artikel35",@"artikel36",@"artikel37",@"artikel38",@"artikel39",@"artikel40",@"artikel41",@"artikel42",@"artikel43",@"artikel44",@"artikel45",@"artikel46",@"artikel47",@"artikel48",@"artikel49",@"artikel50",@"artikel51",@"artikel52",@"artikel53",@"artikel54", nil];

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 14;
}


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    NSArray *sectionTitles = [[NSArray alloc]

initWithObjects:@"Hoofdstuk I.", @"Hoofdstuk
II.",@"Hoofdstuk III.",@"Hoofdstuk IV.",@"Hoofdstuk IVA.",@"Hoofdstuk IVB.",@"Hoofdstuk    

V.",@"Hoofdstuk VA.",@"Hoofdstuk VI.",@"Hoofdstuk VII.",@"Hoofdstuk VII B.",
                                  @"Hoofdstuk VIIC.",@"Hoofdstuk VIII.",nil];

        return sectionTitles;
    }


- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    if ( section == 0 ) return @"Hoofdstuk I. Algemeen";
    if ( section == 1 ) return @"Hoofdstuk II. De instelling";
    if ( section == 2 ) return @"Hoofdstuk III. Samenstelling ";
    if ( section == 3 ) return @"Hoofdstuk IV. Het overleg ";
    if ( section == 4 ) return @"Hoofdstuk IVA. bevoegdheden ";
    if ( section == 5 ) return @"Hoofdstuk IVB. Hgegevens aan de ondernemingsraad";
    if ( section == 6 ) return @"Hoofdstuk IVC. Verdere bevoegdheden van de";
    if ( section == 7 ) return @"Hoofdstuk V. De centrale ";
    if ( section == 8 ) return @"Hoofdstuk VA.";
    if ( section == 9 ) return @"Hoofdstuk VI. De algemene";
    if ( section == 10 ) return @"Hoofdstuk VII.";
    if ( section == 11 ) return @"Hoofdstuk VII. A.de overheid";
    if ( section == 12 ) return @"Hoofdstuk VII. B ";
    if ( section == 13 ) return @"Hoofdstuk VIII";
    return @"Other";
}

To display the right number of rows i used:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ( section == 0 ) return 1;
    if ( section == 1 ) return 4;
... etcetra
return 0;
}

To display the right cell i've used:

if ( indexPath.section == 12  ) mijnRij += 45;   //7a
if ( indexPath.section == 13  ) mijnRij += 56;   //8

cell.textLabel.text = [artikelen objectAtIndex:mijnRij];
return cell;
Was it helpful?

Solution

If you use a better data structure it will make the coding much easier.

I suggest that your main structure should be an array of dictionaries. Each dictionary should match a section and contain two keys. The first key should give you the section header and the second key should give you an array that matches the rows in that section.

That way you don't need so many conditions. The section number tells you which dictionary to use and the row tells you where to look in the dictionary's sub-array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top