簡體   English   中英

發送給不可變對象的變異方法

[英]mutating method sent to immutable object

發送給不變對象的變異方法。

以下是我的代碼:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *strNameEmp = [[NSString alloc]init];

    if (newContactFound == 2 ) {



        strEntered = [phoneArray objectAtIndex:indexPath.row];
        strNameEmp = [availPointsArr objectAtIndex:indexPath.row];

        int IdIndex   = [arrEmpIds indexOfObject:strEntered];
        int nameIndex = [arrEmpName indexOfObject:strNameEmp];




        [arrEmpIds removeObjectAtIndex:IdIndex];
        [arrEmpName removeObjectAtIndex:nameIndex];

首先確保要使用的數組是可變數組。 第二件事,當您從某個地方獲取數組時,請使用語法可變副本。

  mutableArray = [[data valueForKey:@"key"] mutableCopy];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM