appsome / AccordionView

Simple accordion view in Cocoa Touch
Other
144 stars 38 forks source link

How to open by default 2 sections(Headers) when view loads? #23

Open narasimhanallamsetty opened 9 years ago

narasimhanallamsetty commented 9 years ago

Hi,

This is very nice tutorial,exactly what I was looking for. But I need to open 2 sections(Headers) when view loads. Right now I am able to open one section when view loads. How can I open 2 or more sections when view loads.

When I added the below lines section one is opened with animation if (!self.startsClosed && [selectionIndexes count] == 0) { [self setSelectedIndex:0]; }

In the same way I tried for second section, but it's not working for me. May be I need to make changes some where else. if (!self.startsClosed &&[selectionIndexes count] == 2) { [self setSelectedIndex:2]; }

Please help me out. Once again thanks for your great work.

suda commented 9 years ago

Hi @narasimhanallamsetty

first you have to allow multiple selections:

// Set this if you want to allow multiple selection
[accordion setAllowsMultipleSelection:YES];

and then you can set setSelectionIndexes:

[accordion setSelectionIndexes:indexesToOpen];
narasimhanallamsetty commented 9 years ago

Hi @suda

Thanks for the reply, I have set [accordion setAllowsMultipleSelection:YES]; in my ViewController.m

But Where I should call [accordion setSelectionIndexes:indexesToOpen]; code, I am not sure. Could you explain more. Please bear with me. Thank you.

suda commented 9 years ago

You should call setSelectionIndexes where you initialise accordion. indexesToOpen is a NSIndexSet instance containing indexes you want to be opened.

narasimhanallamsetty commented 9 years ago

accordion = [[AccordionView alloc] initWithFrame:CGRectMake(10, 60, 300, [[UIScreen mainScreen] bounds].size.height-30)];

[containerView addSubview:accordion];

[accordion setSelectionIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]];

If I did any mistake please let me know. still it's not working for me.