我浏览了几乎所有的搜索结果,但我的错误并没有消失。我有一个表格视图,每个部分初始化为 2 个部分和 1 行(来自一个数组)。我有一个用于节标题视图的按钮。单击按钮时,我想在第一部分添加一行。这是代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell*)[self.myTableView dequeueReusableCellWithIdentifier:@"DetailCell"];
cell.textLabel.text=[arr objectAtIndex:indexPath.row];
cell.backgroundColor=[UIColor clearColor];
return cell;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
switch (section) {
case 0:
btnReleases=[UIButton buttonWithType:UIButtonTypeCustom];
[btnReleases setFrame:CGRectMake(10, 0, 30, 39)];
[btnReleases setImage:[UIImage imageNamed:@"buttonr.png"] forState:UIControlStateNormal];
[btnReleases addTarget:self action:@selector(loadReleases) forControlEvents:UIControlEventTouchUpInside];
return btnReleases;
break;
case 1:
btnLinks=[UIButton buttonWithType:UIButtonTypeCustom];
[btnLinks setFrame:CGRectMake(10, 0, 30, 39)];
[btnLinks setImage:[UIImage imageNamed:@"buttonl.png"] forState:UIControlStateNormal];
[btnLinks addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
return btnLinks;
break;
default:
break;
}
}
-(void)loadReleases
{
[self.myTableView beginUpdates];
[arr addObject:@"WTF"];
NSArray *insert0 = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]; NSLog(@"%@",insert0);
[self.myTableView insertRowsAtIndexPaths:insert0 withRowAnimation:UITableViewRowAnimationBottom];
[self.myTableView endUpdates];
}
继承人的错误:
* -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046 中的断言失败