Questions tagged [nsindexpath]

The NSIndexPath class represents the path to a specific node in a tree of nested array collections in Objective-C. This path is known as an index path.

Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node. For example, the index path 1.4.3.2 specifies the path shown below:

enter image description here

iOS adds programming interfaces to the NSIndexPath class of the Foundation framework to facilitate the identification of rows and sections in UITableView objects. The API consists of a class method and two properties. The indexPathForRow:inSection: method creates an NSIndexPath object from row and section index numbers. The properties return the row index number and the section index number from such objects

Resource

509 questions
13
votes
3 answers

NSIndexPath does not recognize item, section, or row as properties

When iOS 7.1 sends my viewController: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath The indexPath object does not recognize the properties: item, section or row. …
13
votes
4 answers

Sorting an array of NSIndexPaths

I have an NSMutableArray that contains NSIndexPath objects, and I'd like to sort them by their row, in ascending order. What's the shortest/simplest way to do it? This is what I've tried: [self.selectedIndexPaths…
Eric
  • 16,003
  • 15
  • 87
  • 139
12
votes
2 answers

indexPath.row is always 0

I'm working on populating the table view with an array of dictionaries. The contents of the arrays and the dictionaries are parsed without problems. However, the table is populated with [array count] number of cells with contents with index 0 of the…
Simon Lee
  • 170
  • 1
  • 1
  • 8
12
votes
4 answers

How to check if IndexPath is valid?

Prior to swift 3, i used to use for example: let path = self.tableView.indexPathForSelectedRow if (path != NSNotFound) { //do something } But now, since i use IndexPath class in swift3, i'm looking for the equivalent for the path != NSNotFound…
Lirik
  • 3,167
  • 1
  • 30
  • 31
12
votes
2 answers

Comparing NSIndexPath

This is going to be something really stupid, but I have this code in my cellForRowAtIndexPath: if ([self.indexPathSelected compare:indexPath] == NSOrderedSame) { NSLog(@" %d %d %d %d", self.indexPathSelected.row, self.indexPathSelected.section,…
Jason
  • 1,787
  • 4
  • 29
  • 46
11
votes
2 answers

Why NSIndexPath length always show 2?

I have created a NSIndexPath object but when I print the value of its length property it will always show the value as 2. NSIndexPath *index = [NSIndexPath indexPathForItem:0 inSection:4]; {length = 2, path = 4 - 0} Why length is always 2?
rishu1992
  • 1,414
  • 3
  • 14
  • 33
11
votes
6 answers

iOS: reload single cell of UICollectionView

I am trying to follow the following post on reload a cell in a UICollectionView: UICollectionView update a single cell I know that I ultimately want something that looks like this: [self.collectionView reloadItemsAtIndexPaths:??]; But I don't know…
scientiffic
  • 9,045
  • 18
  • 76
  • 149
9
votes
2 answers

Given model object, how to find index path in NSTreeController?

Given model objects that NSTreeController represents, how do you find their index paths in the tree and subsequently select them? This seems to be a blindingly obvious problem, but I can't seem to find any reference to it. Any ideas?
Tony
  • 36,591
  • 10
  • 48
  • 83
9
votes
2 answers

Decrease indexPath by one

I'm filling a TableView with CoreData. Until now I was doing something like this: NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; ...to retrieve the object to fill the row. Everything was…
Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
9
votes
5 answers

indexPathForRowAtPoint returns nil only for first cell in a uitableview

I have a UIButton inside of a custom UITableViewCell that removes the cell when the button is pressed. In order to get the indexPath of the cell the button is in, I'm calling indexPathForRowAtPoint: in a method called when the button is pressed as…
riocordero
  • 119
  • 1
  • 5
9
votes
3 answers

Issues using NSIndexPath as key in NSMutableDictionary?

Is there any particular reason why attempting to store and retrieve a value in an NSMutableDictionary using an NSIndexPath as a key might fail? I originally attempted to do this in order to store an NSMutableDictionary of UITableViewCell heights…
9
votes
1 answer

UICollectionView indexPathsForVisibleItems don't update new visible cells

I have a ViewController with a CollectionView inside. When the view loads, the visible cells (9 cells) are shown correctly. When I scroll down, I want to load the visible items in the collectionview with loadImagesForOnscreenRows by calling the…
Jan Stulens
  • 141
  • 1
  • 1
  • 3
9
votes
4 answers

How to create indexpaths for all rows and all sections for uitableview?

I have a table with n sections. Each section contains one row. How to create the index path for the table? There is a method that allows to create index path for all visible rows [self.tableView indexPathsForVisibleRows] I need something similar…
Alexey
  • 7,127
  • 9
  • 57
  • 94
8
votes
1 answer

How to convert NSIndexPath to NSInteger?

I have searched and found a previous answer for this question here. The problem is that the answer marked as a solution does not work. Inside my tableView:didSelectRowAtIndexPath: method, I have NSInteger *currentRow = indexPath.row; and it…
tarheel
  • 4,727
  • 9
  • 39
  • 52
8
votes
2 answers

NSIndexPath in Swift

I know, hopefully, that class NSIndexPath deals with arrays which has arrays. I have this code: import UIKit class ViewController: UIViewController, UITableViewDataSource { let devCourses = [ ("iOS App Dev with Swift Essential…
Antonija
  • 173
  • 2
  • 2
  • 9
1 2
3
33 34