Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application Crash on NSIndexPath use in iOS5

Tags:

ios

iphone

#define PROPERTY_SECTION 0
#define SUBTOTAL_ROW 0

UITableViewCell *subtotalCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:SUBTOTAL_ROW inSection:PROPERTY_SECTION]];

When i debug it in ios 6 it working perfect, But in ios 5 app crashed with following reason"

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSIndexPath indexPathForItem:inSection:]: unrecognized selector sent to class 0x1d41f20'
*** First throw call stack:
(0x26b4022 0x2083cd6 0x26b5aad 0x261aed0 0x261acb2 0xc956a 0xc9d4a 0xca3e9 0x12af38f 0x12af5eb 0x12bdb2b 0x12af38f 0x12af5eb 0x12b04ed 0x121da0c 0x26b5e99 0x121e464 0x121e495 0x1222fc1 0x121d14b 0x16864ce 0x162bd61 0x16114d0 0x12ae5ab 0x4ab35 0x14ade29 0x14ad133 0x14ae3bf 0x14b0a21 0x14b097c 0x14a93d7 0x268899e 0x261f640 0x25eb4c6 0x25ead84 0x25eac9b 0x2d167d8 0x2d1688a 0x11e6626 0x248d 0x23b5)
terminate called throwing an exception(lldb) 
like image 689
GhostRider Avatar asked Sep 14 '12 02:09

GhostRider


3 Answers

+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section; is a method only works in UICollectionView in iOS 6. You can't use it in UITableView in iOS 5.

you are probably looking for indexPathForRow:inSection:

like image 62
fannheyward Avatar answered Nov 17 '22 05:11

fannheyward


Use

[NSIndexPath indexPathForRow:indexRow inSection:indexSection];

instead of

[NSIndexPath indexPathForItem:indexRow inSection:indexSection];

like image 26
Umangshu Chouhan Avatar answered Nov 17 '22 06:11

Umangshu Chouhan


It must be a method that is added in iOS6, because it doesn't exist in the iOS5 documentation located here :

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/Reference/Reference.html

Edit: This method is only for a collection view, not a UITableView. Collection views are not supported in iOS 5

like image 4
danielbeard Avatar answered Nov 17 '22 06:11

danielbeard