我想刪除特定索引處的行,但出現此錯誤。因爲它顯示NSArray,但我使用NSMutableArray。不知怎的,它強制類型鑄造。[__NSArrayI removeObjectAtIndex:]:發送到實例的無法識別的選擇器
這兩個數組是全局聲明的。
NSArray *contacts;
NSMutableArray *sortedContacts;
在的cellForRowAtIndexPath方法,我在NSArray中複製的NSMutableArray以顯示其它方式直接使用的NSMutableArray行的數據,鍵值錯過。
contacts = [sortedContacts copy];
這是我在行上的按鈕,按下它,我想刪除所有包含數據的行。
-(void)CancelButtonClicked:(UIButton*)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
[sortedContacts removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
@Larme雖然他沒有在聯繫人上調用removeObjectAtIndex。 – dasblinkenlight
@dasblinkenlight:好點。我現在的問題是哪條線確實導致了崩潰。 – Larme
@Larme我相當肯定這是調用'[sortedContacts removeObjectAtIndex:indexPath.row]',但是在'NSArray'被分配給一個變量時,該變量應該保存對可變數組的引用。 – dasblinkenlight