Reputation: 419
Can somebody please explain the difference between numberOfSectionsInTableView
VS numberOfRowsInSection
?
What does Section imply here? I understand that we've a table with rows. I just can't get to understand Section.
Upvotes: 1
Views: 2063
Reputation: 9589
Explanation
numberOfSectionsInTableView
means UITableview
can have multiple
section.You can give title in Section.numberOfRowsInSection
means each Sections at least should has one
row.
Example:
Fruits
Apple
Orange
PineApple
Guva
Bannana
Vegetable
Onion
Potato
Fruits
,Vegetable
is a Section.
And each section has NumberOfRow
So numberOfSectionsInTableView
return 2 as there are 2 section(Fruits,Vegetable).
And numberOfRowsInSection
return 5 for fruits Section and 2 for vegetable section respectively
Upvotes: 0
Reputation: 6394
Let me explain you with example,
If you would like to display category (Section/Group In short) in your application called, Mobile Devices & Tablets.
In Mobile section you will display list of mobiles where in case of Tablets section you will display list of tablets.
So in above case there is 2 sections & n (n will be number of devices) number of devices/tablets in each section.
Hope it clear your doubt.
Upvotes: 0
Reputation: 1163
Rows in tables can be grouped into sections:
numberOfSections
gives you the number of sections (duh).
numberOfRowsInSection
then gives you the number of rows per section. Sections are optional, it is possible to simply use a single section.
Upvotes: 3
Reputation: 4213
Sections are subdivisions that are filled with rows.
For example, in the Contacts app, each letter is a section that is filled with rows.
A UITableView can be simple with just one section or complex with multiple sections that each have a custom number of rows, header and footer
Upvotes: 0
Reputation: 7948
Section is some kind of groupation, each section has own number of cells.
To have better understanding take a look at phonebook.
Each letter is section, and each section has contacts under that letter.
You can use section to jump to some part of table or to have grouped informations etc.
Another example would be Settings. You have general, security etc.
Upvotes: 0
Reputation: 21
numberOfSectionsInTableView should be default 1 if you just want to have a table with any number of rows.
numberOfRowsInSection is the number of rows you can use in each of your selected sections. (usually you have a data collection and make it the length of this collection)
A section is basically a logic subsection of your table and can have different headers and so on.
Upvotes: 1
Reputation: 513
You can have two types of UITableViews, Plain or Grouped, and you can change that in eg. the tableviews properties in the storyboard. Number of sections refers to the number of sections that the tableview is going to have. A section is a group of Rows, sometimes with a header. Numbers of rows in section refers to the actual number of rows that a section has. So if you have 3 sections, you can define how many rows each section should have.
Upvotes: 0