当我创建自定义类的实例时,我试图自动初始化一个数组:
Sections.h
#import <Foundation/Foundation.h>
@interface Sections : NSObject {
NSMutableArray* allSections;
}
@property(nonatomic, strong) NSMutableArray* allSections;
@end
截面.m
-(void)setAllSections:(NSMutableArray *)allSections {
//--This method sets the array of all the sections available on the app.
NSMutableArray *array = [[NSMutableArray alloc] init];
Section* sectionA = [Section alloc];
sectionA.htmlForExplanation = @"hello";
sectionA.description = @"section a description";
sectionA.name = @"section A";
sectionA.SectionId = 1;
[array addObject:sectionA];
Section* sectionB = [Section alloc];
sectionB.htmlForExplanation = @"hello";
sectionB.description = @"section B description";
sectionB.name = @"section B";
sectionB.SectionId = 2;
[array addObject:sectionB];
[allSections setArray:array.mutableCopy];
}
所以现在当我创建这个实例时,我想要一个预先填充的 allSections 数组
- (void)viewDidLoad
{
//GET DATA FOR SECTIONS POPULATE WEB VIEWS
Sections *sections = [[Sections alloc] init];
//ections setAllSections:<#(NSMutableArray *)#>]
Section* sectionA = [sections.allSections objectAtIndex:0];
Section* sectionB = [sections.allSections objectAtIndex:1];
[webViewA loadHTMLString:sectionA.name baseURL:nil];
[webViewB loadHTMLString:sectionB.name baseURL:nil];
[super viewDidLoad];
}
但是这些对象似乎是空的?这是在objective-c中自动创建数组的正确方法吗?