2013-06-27 1 views
0

행을 삭제하려고하는 섹션이있는 UITableView가 있습니다. BubbleWrap에서 AFMotion으로 전환 할 때 몇 가지 불변의 배열 오류가 발생하기 시작했습니다. 일반적으로 뷰 컨트롤러를 푸시하기 전에 변경할 객체에 mutableCopy를 추가하여 고칠 수 있습니다. 섹션이있는 테이블의 경우 고정 된/변경 불가능한 배열 오류가 발생하지만 NSInternalInconsistencyException: Invalid update: invalid number of rows in section 0이 표시됩니다. 나는 이것들에 대해 다른 질문을 보았고 beginUpdates, endUpdates 등을 추가하려고했지만 여전히 작동하지 않을 것입니다.NSInternalInconsistencyException : 섹션이있는 테이블 뷰의 올바르지 않은 업데이트

def tap_items(sender) 
    controller  = ItemsController.alloc.initWithNibName(nil, bundle:nil) 
    controller.data = @data[:items].mutableCopy 
    self.presentViewController(
    UINavigationController.alloc.initWithRootViewController(controller), 
    animated:true, 
    completion: lambda {} 
) 
end 

다음 ItemsController 내 테이블 설정 : 새 컨트롤러에 데이터가 내가 제시 때 내가 합격

{ 
    "Items" => ["one", "two", "three"], 
    "More" => ["four", "five", "six"] 
} 

:

내 데이터 객체는 다음과 같습니다 해시 다음과 같은 행을 삭제하려면

def tableView(tableView, commitEditingStyle:editingStyle, forRowAtIndexPath:indexPath) 
    if editingStyle == UITableViewCellEditingStyleDelete 
    rows_for_section(indexPath.section).delete_at indexPath.row 
    tableView.deleteRowsAtIndexPaths([indexPath], 
     withRowAnimation:UITableViewRowAnimationFade) 
    end 
end 

하지만 내부 불일치가 발생합니다. e xception 오류. 또한 rows_for_section(indexPath.section).delete_at indexPath.row 대신 data[sections[indexPath.section]].delete_at indexPath.row을 시도했습니다. 그러나 그것은 아무것도 바뀌지 않습니다.

업데이트 : 여기 그것은 어떻게 든 당신은 dataSource의 올바른 인스턴스를 참조하지 않습니다 같은 소리 내있는 tableView

def viewDidLoad 
    super 

    @table = UITableView.alloc.initWithFrame(self.view.bounds) 
    @table.autoresizingMask = UIViewAutoresizingFlexibleHeight 
    self.view.addSubview(@table) 

    @table.dataSource = self 
    @table.delegate = self 
end 

def sections 
    data.keys.sort 
end 

def rows_for_section(section_index) 
    data[self.sections[section_index]].mutableCopy 
end 

def row_for_index_path(index_path) 
    rows_for_section(index_path.section)[index_path.row] 
end 

def tableView(tableView, titleForHeaderInSection:section) 
    sections[section] 
end 

def numberOfSectionsInTableView(tableView) 
    self.sections.count 
end 

def tableView(tableView, numberOfRowsInSection: section) 
    rows_for_section(section).count 
end 
+0

저는 루비 전문가가 아니므로이 동작 방식을 정확히 모르겠지만 원본 데이터 자체를 편집하는 대신 데이터의 변경 가능한 사본 (rows_for_section에서 반환)에서 삭제하지 않는 것이 맞습니까? 당신은 개별적으로 그것들을 변경하려고 시도했지만 양쪽 모두의 데이터와 rows_for_section으로부터 엔트리를 삭제하려고 시도했다고 언급 했습니까? – James

+0

나는 가지고있다. 그러나'고정 된/변경 불가능한 배열을 수정할 수 없다. ' – tvalent2

답변

0

의 코드입니다. 할당 할 위치 (예 : tableView.dataSource = data) 또는 rows_for_section의 코드를 표시하지 않습니다. 나는 그것이 .mutableCopy과 관련이 있는지 궁금해. 그것은 어떤 이유로 필요합니까?

내 앱에서 직접 tableView에서 dataSource를 가져옵니다 (즉, tableView.dataSource).

+0

그냥'rows_for_section' 코드와'dataSource'로 업데이트되었습니다. 감사! – tvalent2

+0

도움이 되었다면 답을 선택하는 것을 잊지 마시고, 환호하십시오. – aceofspades

+0

rows_for_section에서'.mutableCopy'를 제거하면, 불변/고정 배열을 수정할 수 없습니다. 그래서 제가 거기에 넣었습니다. 나는 그것이 내가 무엇을 할 것인지 알기를 원했기 때문에 통과 한 데이터에 추가했습니다. – tvalent2