How to convert NSIndexpath into NSInteger or simply int?

I need to convert a nsindexpath var into NsInteger or simply an int. e.g:

 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 a NSIndexPath..

Please help me how can i achieve this.

Answers


If

NSIndexPath *p = ... // some indexpath

then

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

That's all!


Maybe, this is can help you

NSInteger variable = indexPath.row;

I prefer doing it this way

NSNumber *selRow = [[NSNumber alloc] initWithInteger:indexPath.row];

In Swift:

    let section: Int = indexPath.section
    let row: Int = indexPath.row

Simply convert into int by,

NSIndexPath *path = ... // some indexpath

int row = (int)path.row;


In swift :

  1. Associate your collection view to your var :

    @IBOutlet weak var collectionView: UICollectionView!

  2. In prepareForSegue func, you can call :

    var indexPath = collectionView.indexPathsForSelectedItems()


Need Your Help

Is there a way to subscribe to any emit event on Socket.io?

javascript socket.io frontend

I've got an app that uses socket.io for frontend-backend communication. I've got multiple instances of the socket.emit() function throughout the codebase, and I'd like to know if it's possible to g...

How to redirect console to new window in Java

java eclipse console

I created a program that is console based, but the problem I have is when (Through eclipse) I turn it into a runnable .jar file and run it, nothing happens. I believe this is because it is printing...