-2

In this app I save an NSOrderedSet of cards to a "Subject" entity in core data so that users can quiz themselves. The card flips and drags in tinder like fashion well but in the update card method I'm having some trouble. The current card displays fine as I set that in view did load (the first card of the NSOrderedSet's array property). When I drag and update however it immediately goes to the last card, for example if I have 5 cards in a deck it will start with the first then immediately go to the fifth. What would be the best way to update this method so that it will cycle through as desired?

I suppose I should pass it an index property like a tableViewDelegate method but if someone has done something like this before and has a better way that's greatly appreciated.

Thanks for the help like always.

    func updateCard() {

    //cycle through questions here

    for var i = 0; i < (self.subject.cards?.count)!; i++ {

        self.currentCard = self.subject.cards?.array[i] as? Card
        self.draggableView.questionLabel.text = self.currentCard?.question
        self.draggableView.answerLabel.text = self.currentCard?.answer

    }
}
4

1 回答 1

0

目前,当您调用updateCardfor 循环时,正在以计算机速度进行计算,您只能看到最后一个索引。

这是一个选项:

在您的类中,将名为 selectedCardIndex 的存储变量设置为实现细节,然后在updateCard.

var selectedCardIndex = 0

func updateCard() {

    self.selectedCardIndex += 1
    self.currentCard = self.subject.cards?.array[self.selectedCardIndex] as? Card
    self.draggableView.questionLabel.text = self.currentCard?.question
    self.draggableView.answerLabel.text = self.currentCard?.answer

}
于 2016-01-26T22:30:16.043 回答