没有间歇性地设置变量

时间:2017-06-01 17:16:03

标签: swift

我正在工作的应用程序引导用户完成一次采访,并根据他们的答案发布带有产品推荐的PDF。我目前遇到一些问题,有些手机没有在不可预测的时间正确设置变量。

数据存储在名为“newTracker”的类实例中,并且(对于此问题的范围)答案存储为bool。示例代码来自只有一个问题的屏幕,一个UISwitch和一个“下一步”按钮。

class viewWireVolume: UIViewController {

    // MARK: Properties

    // MARK: Outlets

    @IBOutlet weak var outWireVolume: UISwitch!

    // MARK: Init

    func UIInit(_ animated: Bool) {

        outWireVolume.setOn(newTracker.customerMoreThanOneWire, animated: animated)

    }

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)
        UIInit(false)

    }

    // MARK: Actions

    @IBAction func actionWireVolume(_ sender: Any) { newTracker.customerMoreThanOneWire = outWireVolume.isOn }

    // MARK: Interface

}

大多数情况下,此代码工作正常,但偶尔也不会保存变量newTracker.customerMoreThanOneWire。当它发生时,它会在整个应用程序中发生,并且代码结构相同。我过去遇到过一个问题, 正确地保存了变量,只是没有正确设置初始开关状态,但在这种情况下,它根本不能保存任何东西。

如果将变量设置为Value Change而不是Touch Up Inside会有帮助吗?我很困惑为什么这只会随机发生。 当它发生故障时我手里拿着一部手机,后台没有其他应用程序运行,操作系统已更新,似乎没有像越狱或其他任何事情那样的恶作剧。

我无法使用模拟器或连接到我的开发机器的手机复制此内容。

任何见解?

编辑:这是答案跟踪代码。

class AnswerTracker: NSObject {

// MARK: Variables

/// Name of the business as type: String
var businessName = ""

// Customer Entity Type
var entityType: Int = 0                                     // 0 = None Selected, 1 - 7 = Corp, LLC, Part, LP, SP, NP, Muni

// How will customers pay?
var customerPayCredit: Bool = false
var customerPayChecks: Bool = false
var customerPayCash: Bool = false
var customerPayDirectDebit: Bool = false

// How will checks be deposited?
var customerDepositChecksOffice: Bool = false
var customerDepositChecksBranch: Bool = false
var customerDepositChecksATM: Bool = false
var customerDepositChecksNight: Bool = false

// How will cash be deposited?
var customerDepositCashBranch: Bool = false
var customerDepositCashATM: Bool = false
var customerDepositCashNight: Bool = false

// How will you pay vendors?
var customerPayVendorsOnline: Bool = false
var customerPayVendorsCheck: Bool = false
var customerPayVendorsCredit: Bool = false
var customerPayVendorsDebit: Bool = false
var customerPayVendorsWire: Bool = false
var customerPayVendorsTransfer: Bool = false

// Do you want to stap unauthed checks?
var customerPreventUnauthedChecks: Bool = false

// How will you do wire transfers?
var customerWireInitiateOnline: Bool = false
var customerWireRequestOnline: Bool = false
var customerWireRequestBranch: Bool = false

// Will you regularly do more than one wire per month?
var customerMoreThanOneWire: Bool = false

// How will you pay your employees?
var customerEmployeePayCheck: Bool = false
var customerEmployeePayDirect: Bool = false
var customerEmployeePayCompany: Bool = false

// How will you manage your accounts?
var customerManageAccountsOnlineSingle: Bool = false
var customerManageAccountsOnlineMultiple: Bool = false
var customerManageAccountsBranch: Bool = false

// How will you get your account statements?
var customerAccountStatementsOnline: Bool = false
var customerAccountStatementsPaper: Bool = false

// What will you do with excess funds?
var customerExcessFundsSweep: Bool = false
var customerExcessFundsSavings: Bool = false
var customerExcessFundsCD: Bool = false
var customerExcessFundsFDIC: Bool = false

// How will you handle overdrafts?
var customerOverdraftsLineOfCredit: Bool = false

// Additional lending?
var customerLoansAndLinesFunding: Bool = false
var customerLoansAndLinesRefi: Bool = false

// Would you like to maintain a $3,500 dailyy balance to earn interest?
var customerReceiveInterest: Bool = false

// Would you like to switch your existing accounts to First Federal automatically?
var customerMoveAccounts: Bool = false

// Create a custom class to track answers as someone moves through the app.

override init() // No initialization needed, just a holder in case it's needed in teh future
{
    super.init()
}


/// This function resets ALL of the data stored in the currently instanced AnswerTracker class.
///
/// - Parameter confirm: You must send with "Yes" or the function will not reset the data.
/// - Returns: Returns Bool: true if successful, and Bool: false on failure.
func resetData(confirm: String) -> Bool {

    if confirm == "Yes" {
        businessName = ""
        entityType = 0
        customerPayCredit = false
        customerPayCredit = false
        customerPayChecks = false
        customerPayCash = false
        customerPayDirectDebit = false
        customerDepositChecksOffice = false
        customerDepositChecksBranch = false
        customerDepositChecksATM = false
        customerDepositChecksNight = false
        customerDepositCashBranch = false
        customerDepositCashATM = false
        customerDepositCashNight = false
        customerPayVendorsOnline = false
        customerPayVendorsCheck = false
        customerPayVendorsCredit = false
        customerPayVendorsDebit = false
        customerPayVendorsWire = false
        customerPayVendorsTransfer = false
        customerPreventUnauthedChecks = false
        customerWireInitiateOnline = false
        customerWireRequestOnline = false
        customerWireRequestBranch = false
        customerMoreThanOneWire = false
        customerEmployeePayCheck = false
        customerEmployeePayDirect = false
        customerEmployeePayCompany = false
        customerManageAccountsOnlineSingle = false
        customerManageAccountsOnlineMultiple = false
        customerManageAccountsBranch = false
        customerAccountStatementsOnline = false
        customerAccountStatementsPaper = false
        customerExcessFundsSweep = false
        customerExcessFundsSavings = false
        customerExcessFundsCD = false
        customerExcessFundsFDIC = false
        customerOverdraftsLineOfCredit = false
        customerLoansAndLinesFunding = false
        customerLoansAndLinesRefi = false
        customerReceiveInterest = false
        customerMoveAccounts = false
        return true
    } else {
        return false
    }

}
}

1 个答案:

答案 0 :(得分:0)

在我最初的问题中,我思索着:"如果将变量设置为“价值变化”而非“内部触摸”,它会有所帮助吗?"结果证明是整个解决方案。

出于某种原因,将这些UISwitch操作挂钩到TouchUpInside大部分时间都可以工作。由于它在逐步使用较旧的硬件上运行,因此在切换完成更改其值之前,操作似乎会略微触发,因此将不正确的值写入变量。

我将所有内容都转换为价值变化,从那时起我的测试版组就完美无缺。