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
245
votes
4 answers

How to create NSIndexPath for TableView

I need delete row 1 of a table in a function I have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defined. How can I create an indexpath like this? An array with the int {1} as its only member will…
Rubber Duck
  • 2,947
  • 2
  • 17
  • 23
105
votes
5 answers

Get Selected index of UITableView

I want to have selected index for UITableView. I have written following code: NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; [tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop …
iOSDev
  • 3,607
  • 10
  • 49
  • 90
92
votes
11 answers

Refresh certain row of UITableView based on Int in Swift

I am a beginning developer in Swift, and I am creating a basic app that includes a UITableView. I want to refresh a certain row of the table using: self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.none) and I…
SentientBacon
  • 1,379
  • 2
  • 10
  • 18
84
votes
5 answers

NSIndexpath.item vs NSIndexpath.row

Does anyone know the difference between NSIndexpath.row and NSIndexpath.item? Specifically, which one do I use in: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Cyberpass
  • 1,015
  • 1
  • 7
  • 13
70
votes
2 answers

didSelectRowAtIndexPath returns wrong IndexPath

I have encountered a really puzzling bug. The first row of my UITableView returns 1 and the second one returns 0 in the indexPath! How is that even possible? In my `-(void)viewDidLoad` everything is still fine. I am highlighting the first row…
Mundi
  • 77,414
  • 17
  • 110
  • 132
70
votes
8 answers

How can I get a uitableViewCell by indexPath?

How can I get a UITableViewCell by indexPath? Like this: I use the UIActionSheet, when I click confirm UIButton I want to change the cell text. The nowIndex I define as a property - (void)actionSheet:(UIActionSheet *)actionSheet…
phpxiaoxin
  • 1,035
  • 1
  • 9
  • 9
45
votes
9 answers

How can I check if an indexPath is valid, thus avoiding an "attempt to scroll to invalid index path" error?

How can I check to see whether an indexPath is valid or not? I want to scroll to an indexPath, but I sometimes get an error if my UICollectionView subviews aren't finished loading.
webmagnets
  • 2,172
  • 3
  • 29
  • 54
39
votes
6 answers

tableView section headers disappear SWIFT

I have a tableView set up so that when a cell is touched, it expands in height to reveal more information. The tableView has 5 sections. I have a bug: when a cell expands, all headersCells below that cell go invisible. The console outputs the…
Mason Ballowe
  • 1,749
  • 2
  • 10
  • 19
38
votes
4 answers

Convert NSInteger to NSIndexpath

Basically I am storing an index of an array in a NSInteger. I now need it as an NSIndexpath, I'm struggling to see and find a way to convert my NSInteger to NSIndexpath so I can reuse it.
Dan
  • 1,437
  • 2
  • 13
  • 30
33
votes
2 answers

How to compare two NSIndexPaths?

I'm looking for a way to test if to index paths are equal, and by equal I mean equal on every level? I tried compare: but it seems not to work, I always get true when compared with NSOrderedSame even if the indexes are definitely not the same.
Valentin Radu
  • 8,353
  • 8
  • 57
  • 89
32
votes
1 answer

isEqual doesn't always work for NSIndexPath? What can I use in its place?

I've got some code that relies on comparing two NSIndexPaths and executing different code based on their equality or lack thereof (using -isEqual). Most of the time it works properly, but sometimes it doesn't. I've used the debugger console to test…
JoBu1324
  • 7,633
  • 6
  • 40
  • 59
29
votes
9 answers

How can I get indexPath.row in cell.swift

I have 2 files. myTableViewController.swift myTableCell.swift Can I get the indexPath.row in myTabelCell.swift function? Here is myTableCell.swift import UIKit import Parse import ActiveLabel class myTableCell : UITableViewCell { //Button …
Shawn Baek
  • 1,701
  • 3
  • 16
  • 31
27
votes
2 answers

Comparing NSIndexPath Swift

If I have a NSIndexPath constant declared for a UITableView, is it valid to compare using the == operator? This is my constant declaration: let DepartureDatePickerIndexPath = NSIndexPath(forRow: 2, inSection: 0) And then my function: override…
Shan
  • 2,937
  • 3
  • 19
  • 32
22
votes
8 answers

How can I keep track of the index path of a button in a table view cell?

I have a table view where each cell has a button accessory view. The table is managed by a fetched results controller and is frequently reordered. I want to be able to press one of the buttons and obtain the index path of that button's table view…
Jake
  • 683
  • 1
  • 7
  • 17
21
votes
3 answers

Get the IndexPath from inside a UITableViewCell subclass in Swift

I have a custom UITableViewCell subclass and its associated xib. I have a UILabel and a UIButton in this cell and I have wired the touch up inside action of the button to the subclass. What I need is when that button in the cell is tapped, to get…
Isuru
  • 27,485
  • 56
  • 174
  • 278
1
2 3
33 34