Access NSMutableArray from another class - Objective C

前端 未结 5 1808
清歌不尽
清歌不尽 2020-12-22 06:34

I have a main ViewController that contains a desginated class. Within that ViewController there is a Container that is linked to an <

5条回答
  •  情书的邮戳
    2020-12-22 07:00

    What you've done in the code provided is set a public property for a mutable array...

    @property (strong, nonatomic) NSMutableArray *selectedCells;
    

    The NSMutableArray is not "created" by setting that property. At some point in your code you also have to create the NSMutableArray by initialising...

    NSMutableArray *selectedCells = [[NSMutableArray alloc] init];
    

    or by using a convenience method such as...

    NSMutableArray *selectedCells = [NSMutableArray arrayWithCapacity:(NSUInteger)];
    

    or

    NSMutableArray *selectedCells = [NSMutableArray arrayWithArray:(NSArray *)];
    

    Initialising an NSMutableArray is often done only once. If it is repeated, the contents are overwritten against the property used to point to the array. As such, a useful location for this is often within the viewDidLoad view controller lifecycle method.

提交回复
热议问题