![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create NSIndexPath for TableView in iOS?
Index path is generally a set of two values representing row and section of a table view. Index path can be created in objective C as well as Swift as both are native language of iOS Development.
IndexPathForRow is a class method in iOS. To create a index path we need to be sure about the section and row we need to create. Below are the methods of creating an Indexpath.
To create an IndexPath in objective C we can use.
NSIndexPath *myIP = [NSIndexPath indexPathForRow: Int inSection:Int] ;
Example
NSIndexPath *myIP = [NSIndexPath indexPathForRow: 5 inSection: 2] ;
To create an IndexPath in Swift we can use.
IndexPath(row: rowIndex, section: sectionIndex)
Example
IndexPath(row: 2, section: 4)
Both of these are generally used in Cell for row at method, which can be used as
let cell = tblView.cellForRow(at: IndexPath(row: 5, section: 2)
Advertisements