2017-03-29 2 views
0

I 클래스 카드 (포함 배열의 사전도)를 가지고, 내 카드는 이동에 대해 하나의 배열잘못된 번호 스위프트 3

static var DeliveryStatusArray = 
    [ 
     "claimable": [Card](), 
     "onTime": [Card](), 
     "future": [Card](), 
     "claimDone": [Card](), 
     "tooOld": [Card](), 
    ] 

내 fonction 이동 함수를 호출 버튼을

static func moveCard(card:Card) -> Void { 
    var pos:Int = -1 
    var index:Int = 0 
    while(index < (DashboardManager.DeliveryStatusArray["claimable"]?.count)!) 
    { 
     if (DashboardManager.DeliveryStatusArray["claimable"]?[index].idCard == card.idCard) 
     { 
      pos = index 
     } 
     index += 1 
    } 
    if (pos > -1) 
    { 
     let card:Card = (DashboardManager.DeliveryStatusArray["claimable"]?[pos])! 
     DashboardManager.DeliveryStatusArray["claimable"]?.remove(at: pos) 
     DashboardManager.DeliveryStatusArray["claimDone"]?.append(card) 
    } 
} 

이이 기능을

func notificationFinish(notification:Notification) -> Void{ 
     let sectionClaimable:Int = (api.dictionary["delivery"]?.index(of: "claimable"))! // Is 1 
     let sectionClaiDone: Int = (api.dictionary["delivery"]?.index(of: "claimDone"))! // Is 4 
     tableView.reloadSections(IndexSet(integer: sectionClaimable), with: .top) 
     tableView.reloadSections(IndexSet(integer: sectionClaimDone), with: .top) 
     return 
    } 

첫 번째 루프 I를 호출 내보기로 알림을 게시 할 때 나는 세 가지 카드를

이 [ "claimDone] * 및 moveCard()를 호출 한 후 * DeliveryStatusArray에서 카드를 2 장있어 나는 때문에 캐치되지 않는 예외 'NSInternalInconsistencyException'응용 프로그램 종료 오류

***

있어, 이유 : '유효하지 않은 업데이트 : 섹션 4의 행 개수가 잘못되었습니다. 업데이트 (3) 후 기존 섹션에 포함 된 행 수는 업데이트 (2) 이전에 해당 섹션에 포함 된 행 수와 같아야합니다. 그 섹션 (삽입 된 0, 삭제 된 0)에서 삽입되거나 삭제 된 행의 수를 뺀 것과 그 섹션 (0이 이동, 0이 이동 됨)으로 들어갔다 나오는 행 수를 더하거나 뺍니다. '

데이터를 새로 고침 할 때 더 많은 항목을 가져올 수 없습니까?

+4

맨 끝 ... 소문자, 예를 들어, 사용하여 속성 이름을 시작 ... 그것은 할 필요보다 훨씬 더 복잡하다 클래스와 구별하는'deliveryStatusArray' –

+0

팁 주셔서 감사합니다! –

+0

'moveCard'가 _supposed_에 무엇을 설명 할 수 있습니까? –

답변

0

내가 제대로 이해한다면, 당신의 코드는

// Get the index of card in claimable with matching idCard 
guard let index = deliveryStatusArray["claimable"]?.index(where: {$0.idCard == card.idCard }) else { return } 

// Remove the card at that index 
let card = deliveryStatusArray["claimable"]?.remove(at: index) 

// Append the card 
deliveryStatusArray["claimDone"]?.append(card)