hello i am wondering how its possible to add an index for a tableview to an array. i am trying to save this index to the array in order to be able to view it later. i just am interested in knowing how to save the index to the array. thanks
+1
A:
Use a NSMutableArray
and send it an addObject:
message with the NSIndexPath
as an argument.
tob
2010-08-17 11:21:48
This is very useful: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/Reference/Reference.html - NSIndexPath's actual documentation does not contain the most useful bits!
Adam Eberbach
2010-08-17 11:52:15
A:
Same way you save anything to an array:
NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject:myIndexPath];
Dan Ray
2010-08-17 13:04:33
i tried this however im getting indexPath undeclared and confused by earlier erros bailing out... NSMutableArray *favorites =[[NSMutableArray favorites]; [favorites addObject:indexPath];
Alx
2010-08-17 13:12:35
There's no such class method as `[NSMutableArray favorites]`, and your double `[[` before that is a syntax error. What I said above is `NSMutableArray *myArray = [NSMutableArray array]`, which returns an autoreleased, empty NSMutableArray and assigns it to the pointer myArray.
Dan Ray
2010-08-17 13:38:07
yes sorry i fixed those errors without realizing i pasted them however after all this i get a crash everytime it reaches this code.i have this code NSMutableArray *favorites = [NSMutableArray favorites]; NSIndexPath *indexPath = [NSIndexPath indexPath]; [favorites addObject:indexPath];and i put it in the viewDidLoad part of my second table view...it crashes as soon as i click on that part. i have 2 hierachial table views with 2 detail view controllers.
Alx
2010-08-17 14:04:42
So, again, there's no such thing as `[NSMutableArray favorites]`. You've now added another thing there's no such thing as, `[NSIndexPath indexPath]`. If you look in the console, you'll see it's dying because 'favorites' is an unrecognized selector on the class NSMutableArray.
Dan Ray
2010-08-17 14:52:40