I am trying to store all of the items scrolled past in my UITableView in an NSMutableArray. In my cellForRowAtIndexPath
method I include the code below. All of the objects (Id, currentTime, et...) are NSStrings.
I am trying to compile all of them into a single array, but I don't think I am doing this correctly. I think I might be overwriting the dictionary in every single cellForRowAtIndexPath
.
Any help would be great. At the end, I just want a single array that allows me to look up various aspects of the "rows/cells" that were scrolled past...
In my .m file:
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:Id forKey:@"key1"];
[dict setObject:currentTime forKey:@"key2"];
[dict setObject:textForMyLabel forKey:@"key3"];
[dict setObject:placeLatitude forKey:@"key4"];
[dict setObject:placeLongitude forKey:@"key5"];
[scrolledPast addObject:dict];
NSLog(@"array: %@", dict);
In my .h file:
@interface viewController {
NSMutableArray *scrolledPast;
}
@property (nonatomic, retain) NSMutableArray *scrolledPast;
You need to initialize your scrolledPast
.
Do this in your viewDidLoad:
- (void) viewDidLoad {
// .....
scrolledPast = [NSMutableArray array];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.