自动删除领域对象

时间:2019-06-12 12:03:31

标签: ios objective-c xcode realm

我正在尝试一个示例领域代码,并且添加了一个选项,该选项可以根据特定值自动删除特定对象。但是我需要做的是重新加载tableview,但是当我添加[baseTableView reloadData]时;该应用程序崩溃,出现异常“对象已被删除或无效”。有谁知道我该如何解决这个问题,以便Tableview更新并删除自动删除的行。我的删除代码是:

-(IBAction)delline:(id)sender
{




NSInteger count = [QueueArray count];
for (NSInteger index = (count - 1); index >= 0; index--) {
    person = QueueArray[index];
    if ([person.emailaddress1 isEqualToString:@"test"]) {

          NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
            [dbManager deleteRealmObject:[QueueArray objectAtIndex:index]];
            NSLog(@"DELETE PATH: %ld", (long)index);
            // set to whatever you want to be selected first
            [baseTableView selectRowAtIndexPath:indexPath animated:NO  scrollPosition:UITableViewScrollPositionNone];

            UITableViewCell *cell = [baseTableView cellForRowAtIndexPath:indexPath];

            cell.userInteractionEnabled = NO;
            cell.textLabel.text = @"UPLOADED SUCCESSFULLY";
            cell.detailTextLabel.text = @"";
        [baseTableView reloadData];

    }

}


}

0 个答案:

没有答案