I am having some trouble trying to share a NSMutableArray
of Strings to another class. I have a tableView
that is populated with Strings
that I would like to add to a NSMutableArray
. Then use that SAME NSMutableArray
in another ViewController
I have created a class with the subclass of NSMutableArray
.h
#import <Foundation/Foundation.h>
@interface HYServicesMArray : NSMutableArray
@property (nonatomic, weak)NSMutableArray * arrServicesUserChoice;
@end
.m
#import "HYServicesMArray.h"
@implementation HYServicesMArray
@dynamic arrServicesUserChoice;
@end
I am trying to add elements to this NSMutableArray
from a tableView didSelectRowAtIndexPath:
.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"You have selected: %@",cell.textLabel.text);
// add cell.textLabel.text to arrServicesUserChoice
// Tried the code below but causes my app to crash
arrServicesUserChoice = [[NSMutableArray alloc]init];
[arrServicesUserChoice addObject:cell.textLabel.text];
}
How ever I am unable to add elements to the arrServicesUserChoice
. I am stuck please help! Thank you in advance!