我有一個小的問題,ARC和dealloc的BaseViewController類在循環內實例化後被調用,我不知道爲什麼。我想要做的是基本上將所有的基本視圖控制器存儲在一個數組上。爲什麼在實例化之後立即調用dealloc?
@interface CategoriesContainerViewController()
@property (nonatomic, strong) IBOutlet UIScrollView* scrollView;
@property (nonatomic, strong) NSMutableArray* categoriesViews;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// Get the categories from a plist
NSString* path = [[NSBundle mainBundle] pathForResource:@"categories" ofType:@"plist"];
NSDictionary* dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSMutableArray* categories = [dict objectForKey:@"Categories"];
NSLog(@"%i", [categories count]);
// Setup the scrollview
_scrollView.delegate = self;
_scrollView.directionalLockEnabled = YES;
_scrollView.alwaysBounceVertical = YES;
_scrollView.scrollEnabled = YES;
CGRect screenRect = [[UIScreen mainScreen] bounds];
// Loop through the categories and create a BaseViewController for each one and
// store it in an array
for (int i = 0; i < [categories count]; i++) {
BaseViewController* categoryView = [[BaseViewController alloc]
initWithCategory:[categories objectAtIndex:i]];
CGRect frame = categoryView.view.frame;
frame.origin.y = screenRect.size.height * i;
categoryView.view.frame = frame;
[_scrollView addSubview:categoryView.view];
[_categoriesViews addObject:categoryView];
}
}
你曾經實例化'categoriesViews'嗎? – Wain
你是對的@很好!它現在按預期工作。 – 72lions