How to convert NSIndexpath into NSInteger or simply int?

后端 未结 6 1019
轻奢々
轻奢々 2021-01-30 20:34

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

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


        
相关标签:
6条回答
  • 2021-01-30 20:52

    If

    NSIndexPath *p = ... // some indexpath
    

    then

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

    That's all!

    0 讨论(0)
  • 2021-01-30 20:55

    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()

    0 讨论(0)
  • 2021-01-30 21:07

    Maybe, this is can help you

    NSInteger variable = indexPath.row;
    
    0 讨论(0)
  • 2021-01-30 21:07

    In Swift:

        let section: Int = indexPath.section
        let row: Int = indexPath.row
    
    0 讨论(0)
  • 2021-01-30 21:08

    I prefer doing it this way

    NSNumber *selRow = [[NSNumber alloc] initWithInteger:indexPath.row];
    
    0 讨论(0)
  • 2021-01-30 21:10

    Simply convert into int by,

    NSIndexPath *path = ... // some indexpath

    int row = (int)path.row;

    0 讨论(0)
提交回复
热议问题