在我的应用程序中,我重新加载 TableView([tablView reloadData];
)从 TableView 中删除行后canEditRowAtIndexPath
方法总是调用(透水)总行数。
例如:
如果我有5我的 TableView 上的行,然后我删除1来自 tableView 的行。删除后我reload我的表格视图([tablView reloadData]
) but canEditRowAtIndexPath
方法调用5 time代替4 times ??
所以我总是得到关注Error:
由于未捕获的异常“NSRangeException”而终止应用程序,reason: '* **-[__NSArrayM objectAtIndex:]: 索引 5 超出范围 [0 .. 4]'
我还尝试在延迟一段时间后重新加载表(使用NSTimer
)但它对我也不起作用。
我在这里放了一些代码:
I apply canEditRowAtIndexPath
在特定行上@"status" isEqualToString:@"directory"
诸如此类,
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%d", self.listOfSounds.count);
// Return NO if you do not want the specified item to be editable.
if([[[self.listOfSounds objectAtIndex:indexPath.row] objectForKey:@"status"] isEqualToString:@"directory"])
return YES;
else
return NO;
}
删除行代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[self.sql_ deleteSoundFileAudioTableWhereMainID:[[self.listOfSounds objectAtIndex:indexPath.row] objectForKey:@"main_id"]]; /// delete record from DB
[self.listOfSounds removeObjectAtIndex:indexPath.row]; /// delete record from Array
[self updateListofSoundsFile]; /// Custom method
}
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO; // i also tried to return YES;
}
Here updateListofSoundsFile
我的自定义方法代码是:
-(void)updateListofSoundsFile
{
if(self.listOfSounds.count > 0)
[self.listOfSounds removeAllObjects];
self.listOfSounds = [self.sql_ getAllDataFromAudioTable]; // get all record from DB
NSLog(@"%d",self.listOfSounds.count);
[self.tblView reloadData];
}
请给出任何建议,我该如何解决这个问题?
谢谢 :)