What is the exact meaning of indexPath.section?

From Apple's documentation on the indexPathForRow method, I don’t understand when and how to use indexPath.section, and I don’t understand what exactly means “section”. I am new to iPhone development, can someone please help me explain the “section” a bit?

From the UIKits documentation:

row

The index number identifying the row in the UITableView in the section defined by the section.

section

The index number identifying the section in the UITableView.

+6
source share
4 answers

enter image description here

I hope you understand what the section means. I think you already know. If you have any doubt as a comment.

+10
source

You may have sections of strings . There is always at least one section to view the table. You can use the numberOfSections method to change this. Similarly, tableView:numberOfRowsInSection: indicates how many rows are in this section. And finally, tableView:cellForRowAtIndexPath: gives the cell the specified row and section. For example, in the contacts application, each alphabet is a section. Its lines are all names starting with this letter. For example, "S" will have "Samuel," "Sarah." Similarly, “A” will have “Ali,” “Alex.” I suggest you read this carefully.

+1
source

The section and line of the index path are a special case (in fact, the extension for NSIndexPath for UIKit , see this post ). For a given NSIndexPath indexPath

 [indexPath indexAtPosition:0]; 

coincides with

 [indexPath section]; 

and

 [indexPath indexAtPosition:1]; 

coincides with

 [indexPath row]; 

This makes it more intuitive to handle paths in table views that have sections and a given number of rows for each section.

+1
source

Each table has sections and rows in this section. indexPath.row and indexPath.section respectively refer to different parts.

0
source

Source: https://habr.com/ru/post/899989/


All Articles