 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
 