UITableView に新しいセクションを挿入するのに苦労しています。基本的に達成したいことは次のとおりです。-各セクションが各年に対応するカレンダーを作成しようとしています。各セクションには 30 個のセルがあります。
最初のセクションはかなりうまくロードされますが、最初のセクションの 8 番目のセルに移動すると、新しいセクションを挿入しようとします
sectionNo =1; //in viewDidLoad method
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 10 && indexPath.section == sectionNo-1)
{
sectionNo = sectionNo+1;
[mainTable insertSections:[NSIndexSet indexSetWithIndex:sectionNo-1] withRowAnimation:UITableViewRowAnimationNone]; //APPLICATION CRASHES HERE ERROR IS "Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
"
}
}
//読み取るセクションの数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return sectionNo; //count of section
}
//セクションごとの行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 12;
}
//行メソッドの CEll は次のように読み取ります
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = @"Hello";
return cell;
}
興味深いことに、すばやくスクロールしないとクラッシュしないことがあります。しかし、10行目から11行目までゆっくりスクロールすると、クラッシュしないことがあります