我的应用程序有问题。问题是当我按下 AlertView 上的取消按钮时。它没有显示应该出现在我的输出中的“取消”文本。确认和显示密码按钮工作正常,都显示 NSLogs,只有取消按钮不显示。这是我的代码。请耐心等待我,因为我是 Xcode 的新手。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Confirm"])
{
UITextField *password = [alertView textFieldAtIndex:0];
NSLog(@"Password: %@", password.text);
if (buttonIndex != [alertView cancelButtonIndex])
{
NSLog(@"cancel");
}
else
{
NSLog(@"confirm");
entries = [[NSMutableArray alloc]init];
NSString *select = [NSString stringWithFormat:@"SELECT * FROM summary2 WHERE username = '%s' and pass = '%s'",[self.lbUser.text UTF8String],[password.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(user, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
{
if(sqlite3_step(statement)==SQLITE_ROW)
{
NSLog(@"database updated");
[self updatedatabase];
UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:@"Done" message:@"Account was updated successfully!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert3 show];
}
else
{
NSLog(@"Authentication Failed!");
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Wrong Password! Account was not updated." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert2 show];
NSLog(@"fail");
}
}
}
}
else if([title isEqualToString:@"View Password"])
{
UITextField *password = [alertView textFieldAtIndex:0];
NSLog(@"Password: %@", password.text);
if (buttonIndex != [alertView cancelButtonIndex])
{
NSLog(@"cancel");
}
else
{
NSLog(@"confirm");
entries = [[NSMutableArray alloc]init];
NSString *select = [NSString stringWithFormat:@"SELECT * FROM summary2 WHERE username = '%s' and pass = '%s'",[self.lbUser.text UTF8String],[password.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(user, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
{
if(sqlite3_step(statement)==SQLITE_ROW)
{
NSLog(@"database updated");
[self switchbtn];
}
else
{
//switch1.on=YES;
NSLog(@"Authentication Failed!");
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Failed" message:@"Wrong Password! Cannot view password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert2 show];
NSLog(@"fail");
}
}
}
}
}