Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an NSIndexPath from an int?

Tags:

Error message:

cast of 'int' to "NSIndexPath *' is disallowed with ARC

Code:

NSInteger CurrentIndex;

[self tableView:(UITableView *)horizontalTableView1 didSelectRowAtIndexPath:(NSIndexPath *)int_CurrentIndex];

How do I fix this error?

like image 986
Deepak R Avatar asked Oct 21 '12 11:10

Deepak R


1 Answers

You can't cast an int variable to an NSIndexPath directly. But you can make an NSIndexPath from an int variable.

You need a section index and row index to make an NSIndexPath. If your UITableView has only one section then:

Objective-C

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];

Swift

let indexPath: NSIndexPath = NSIndexPath(forRow: rowIndex, inSection: 0)

Swift 4

let indexPath = IndexPath(row: rowIndex, section: 0)
like image 74
TheTiger Avatar answered Oct 09 '22 00:10

TheTiger