在swift

时间:2015-07-30 03:49:20

标签: ios arrays swift

此代码的主要目标是用户能够在应用程序中突出显示/喜欢页面。我有一个引号数组,用户在按钮点击时滚动。 我想拥有它,以便在点击“收藏”按钮时(尚未在代码中实现)。提取用户正在查看的当前元素(整个字符串?)然后以某种方式标记/发送到另一个数组。然后使用我自己的方法显示此数组。我不知道如何做到这一点。这是我的viewcontroller文件。

import UIKit

class DreamViewController: UIViewController {

    @IBOutlet var QuoteImage: UIImageView!
    @IBOutlet weak var DreamLabel: UILabel!
    var counter = 1

    var factIndex = 0

    let dreamFact = Dream()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        DreamLabel.text = dreamFact.dreamArray[factIndex]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func LeftSwipe() {
        factIndex--
        var number = dreamFact.dreamArray.count - 1
        if (factIndex < 0){
            self.factIndex = number

        }
        DreamLabel.text = dreamFact.dreamArray[factIndex]
        if counter == 1 {

            counter = 36

        } else {

            self.counter--

        }

        QuoteImage.image = UIImage(named: "frame\(counter).jpg")

    }





    @IBAction func RightSwipe() {
        factIndex++
        if factIndex >= dreamFact.dreamArray.count {
            self.factIndex = 0
        }
        DreamLabel.text = dreamFact.dreamArray[factIndex]



    if counter == 36 {

    counter = 1

    } else {

    self.counter++

    }

    QuoteImage.image = UIImage(named: "frame\(counter).jpg")

}
}

如果需要任何其他信息,请尽快告诉我。谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用您用来跟踪当前索引的factIndex,从dreamArray中删除用户喜欢的特定“引用”。看到factIndex在跟踪用户正在查看的当前引用时是正确的,我们知道我们可以使用它来从数组中提取正确的对象。

以下建议假定您创建一个数组来存储您喜欢的引号,例如......

var favouriteQuotesArray: [String] = []

func makeQuoteFavourite() {

    let currentQuote = dreamFact.dreamArray[factIndex]
    favouriteQuotesArray.append(currentQuote)
}
相关问题