在 for 循环中加载 NibNamed 时崩溃
Crash when loadingNibNamed in for loop
这是以下问题的延续
基本上我在打电话
[[NSBundle mainBundle] loadNibNamed:@"YFCalendarDayCell" owner:self options:nil] objectAtIndex:0];
或
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName
owner:nil
options:nil];
在 for 循环中。这最终会因返回的 BadExcess error
OR NSArray
具有零元素而崩溃。
有正确的方法吗?
添加后@Autoreleasepool
int i, j, k=0;
for( i=0; i<5; i++ )
{
for( j=0; j<7; j++ )
{
@autoreleasepool {
YFCalendarDayCell *tableView = [Utility loadNibNamed:@"YFCalendarDayCell" ofClass:[YFCalendarDayCell class]];
tableView.cellTableView.dataSource = tableView;
tableView.cellTableView.delegate = tableView;
tableView.controller = mainViewController;
//[calendarView addSubview:tableView];
NSLog(@"tables added to calendar view i: %d j: %d",i,j);
[calendarView.CellDict setObject:tableView forKey:[[NSNumber numberWithInt:k++] stringValue]];
}
}
}
试试下面的答案
for (i=0; i<5; i++) {
@autoreleasepool
{
for (j=0; j<7; j++)
{
YFCalendarDayCell *tableView = [Utility loadNibNamed:@"YFCalendarDayCell" ofClass:[YFCalendarDayCell class]];
tableView.cellTableView.dataSource = tableView;
tableView.cellTableView.delegate = tableView;
tableView.controller = mainViewController;
NSLog(@"tables added to calendar view i: %d j: %d",i,j);
[calendarView.CellDict setObject:tableView forKey:[[NSNumber numberWithInt:k++] stringValue]];
}
}
}
这是以下问题的延续
基本上我在打电话
[[NSBundle mainBundle] loadNibNamed:@"YFCalendarDayCell" owner:self options:nil] objectAtIndex:0];
或
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName
owner:nil
options:nil];
在 for 循环中。这最终会因返回的 BadExcess error
OR NSArray
具有零元素而崩溃。
有正确的方法吗?
添加后@Autoreleasepool
int i, j, k=0;
for( i=0; i<5; i++ )
{
for( j=0; j<7; j++ )
{
@autoreleasepool {
YFCalendarDayCell *tableView = [Utility loadNibNamed:@"YFCalendarDayCell" ofClass:[YFCalendarDayCell class]];
tableView.cellTableView.dataSource = tableView;
tableView.cellTableView.delegate = tableView;
tableView.controller = mainViewController;
//[calendarView addSubview:tableView];
NSLog(@"tables added to calendar view i: %d j: %d",i,j);
[calendarView.CellDict setObject:tableView forKey:[[NSNumber numberWithInt:k++] stringValue]];
}
}
}
试试下面的答案
for (i=0; i<5; i++) {
@autoreleasepool
{
for (j=0; j<7; j++)
{
YFCalendarDayCell *tableView = [Utility loadNibNamed:@"YFCalendarDayCell" ofClass:[YFCalendarDayCell class]];
tableView.cellTableView.dataSource = tableView;
tableView.cellTableView.delegate = tableView;
tableView.controller = mainViewController;
NSLog(@"tables added to calendar view i: %d j: %d",i,j);
[calendarView.CellDict setObject:tableView forKey:[[NSNumber numberWithInt:k++] stringValue]];
}
}
}