How to convert NSIndexpath to NSInteger or just int?

I need to convert var nsindexpath to NsInteger or just int. eg:

int rowIndex = [mGoogleBaseTable selectedRow]; //mGoogleBaseTable is a NSTable type in Macdevelopement.. 

& &

 int rowIndex = [mGoogleBaseTable indexPathForSelectedRow]; //mGoogleBaseTable is a UITableView type in Iphone (iOS)Development. 

selectedRow returns NSInteger simply, but indexPathForSelectedRow returns NSIndexPath ..

Please help me how can I achieve this.

+47
iphone cocoa-touch
Jan 01 '10 at 15:07
source share
6 answers

If

 NSIndexPath *p = ... // some indexpath 

then

 NSInteger row = p.row; NSInteger section = p.section; 

What all!

+123
Jan 01 '10 at 15:12
source share
— -

Perhaps this can help you.

 NSInteger variable = indexPath.row; 
+13
Apr 21 2018-12-21T00:
source share

In Swift :

  let section: Int = indexPath.section let row: Int = indexPath.row 
+7
Jun 20 '15 at 0:47
source share

I prefer to do it this way

 NSNumber *selRow = [[NSNumber alloc] initWithInteger:indexPath.row]; 
+6
Jan 01 2018-11-11T00:
source share

Just convert to int by,

NSIndexPath * path = ... // some index path

int row = (int) path.row;

+1
May 19 '16 at 7:13
source share

In quick:

  • Link your collection to your var:

    @IBOutlet weak var collectionView: UICollectionView!

  • In prepareForSegue func you can call:

    var indexPath = collectionView.indexPathsForSelectedItems ()

-one
Oct 06 '14 at 20:26
source share



All Articles