【发布时间】:2015-03-25 10:57:22
【问题描述】:
我在 for- 循环中分配自定义对象(本例中为视图控制器)。一切似乎都很好。但是当我点击 viewcontroller 的第一个自定义对象的按钮时,应用程序崩溃了。 这是因为未保留自定义对象的实例。虽然它适用于最后添加的对象。 请指教。
dispatch_async(dispatch_get_main_queue(), ^{
NSInteger index = 0;
for (TestStep *obj_Teststep in objTestSuite.testSteps) {
TestStepView * obj_TestStepView = [[TestStepView alloc] initWithNibName:@"TestStepView" bundle:[NSBundle mainBundle]];
obj_TestStepView.testStep = obj_Teststep;
obj_TestStepView.delegate = self;
DMPaletteSectionView *sectionView = [[DMPaletteSectionView alloc] initWithContentView:obj_TestStepView.view andTitle:[NSString stringWithFormat:@"Test Step %@ - %@",obj_Teststep.executionOrder,obj_Teststep.apiCallPath] initialState:DMPaletteStateCollapsed withAction:YES andIndex:index];
sectionView.layer.backgroundColor = [NSColor redColor].CGColor;
[sectionArray addObject:sectionView];
index++;
}
[sectionArray addObject:[[DMPaletteSectionView alloc] initWithContentView:self.addNewTestStepView andTitle:@"Add Test Step" initialState:DMPaletteStateExpanded withAction:NO andIndex:0]];
container.sectionViews = sectionArray;
for (int i =0; i<container.sectionViews.count; i++) {
DMPaletteSectionView *dmobj = [container.sectionViews objectAtIndex:i];
dmobj.delegate = self;
}
});
【问题讨论】:
标签: ios objective-c cocoa memory-management retain