1

次の質問の続きです

https://stackoverflow.com/questions/39673003/crash-on-multiple-calls-to-loadnibnamed

基本的に私は電話しています

[[NSBundle mainBundle] loadNibNamed:@"YFCalendarDayCell" owner:self options:nil] objectAtIndex:0];

また

NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName
                                                     owner:nil
                                                   options:nil];

forループで。これは最終的にクラッシュし、返されるBadExcess errorORNSArrayには要素がありません。

これを行う正しい方法はありますか?

追加後@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]];
        }
    }
}
4

1 に答える 1

1

以下の回答を試してください

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]];
          }
      }
}
于 2016-09-26T10:36:15.993 に答える