我正在使用swift在iOS应用中构建注册/登录系统。我设置了一个DynamoDB表,我可以从该表发送和加载数据。但是,当我尝试扫描表时,我遇到了一个问题。我正在使用扫描检查并确保电子邮件,用户名和密码是原始的。扫描功能工作并将所有数据都关闭,但是当我尝试使用数据时就像我说的那样:
let results = task.result as! AWSDynamoDBPaginatedOutput
for r in results.items{
if (self.emailTextField.text == r.userEmail){
self.emailMessageLabel.hidden = false
self.emailTextField.text = nil
}
整个功能变得混乱。因为它做的是检查emailTextField是否等于任何结果,即使它是一次,所有其他时间都不是。所以它会说emailMessageLabel.hidden是真实的,因为emailTextField不等于任何东西,并且假一次是false。所以基本上答案都是真的和假的,我不能使用那些数据。我该如何解决?我一直试图修复它好几天。我将附上我一直试图使用的所有代码。
扫描功能
func verifyAndActivateAccount(expression : AWSDynamoDBScanExpression) {
self.emailMessageLabel.hidden = true
self.nameMessageLabel.hidden = true
self.passwordMessageLabel.hidden = true
let tableRow = DDBTableRow()
let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
dynamoDBObjectMapper.scan(DDBTableRow.self, expression: expression) .continueWithExecutor(BFExecutor.mainThreadExecutor(),
withBlock: { (task:BFTask!) -> AnyObject! in
if (task.error == nil) {
let results = task.result as! AWSDynamoDBPaginatedOutput
for r in results.items{
if (self.emailTextField.text == r.userEmail){
self.emailMessageLabel.hidden = false
}
if (self.nameTextField.text == r.UserID) {
self.nameMessageLabel.hidden = false
}
if (self.passwordTextField.text == r.userPassword){
self.passwordMessageLabel.hidden = false
}
}
}else{
self.giveSignUpAlert("Scan didn't work.")
}
return nil
})
}
按下按钮
@IBAction func storeRegisterInfo(sender: UIButton) {
let exp = AWSDynamoDBScanExpression()
self.verifyAndActivateAccount(exp)
//Check for original info
let tableRow = DDBTableRow()
tableRow?.UserID = self.nameTextField.text
tableRow?.userEmail = self.emailTextField.text
tableRow?.userPassword = self.passwordTextField.text
let userEmail = emailTextField.text
let userName = nameTextField.text
let userPassword = passwordTextField.text
let userConfirm = confirmTextField.text
if userPassword != userConfirm {
giveSignUpAlert("Your Passwords Don't Match!")
}
if (self.passwordTextField.text == self.confirmTextField.text) {
if (userEmail.isEmpty || userName.isEmpty || userPassword.isEmpty || userConfirm.isEmpty){
giveSignUpAlert("All Field Are Required")
}else{
self.insertDataIntoTable(tableRow)
}
}
}
答案 0 :(得分:0)
您可以使用以下几种方法: