由於某些原因,此代碼不會按順序執行。 Xcode似乎正在評估if-else語句,然後在顯示if-else語句之前的UIAlertView
之前顯示if-else語句中的UIAlertView
。代碼不會按順序執行
下面是我供你參考代碼:
- (IBAction)btnLogin:(id)sender; {
//self.tbxUsername.text = [NSString stringWithFormat:@"vmcv"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email"
message: [NSString stringWithFormat: @"%@", acc.Email]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
if([self.tbxUsername.text isEqualToString:acc.Email ])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication"
message: @"Success"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication"
message: @"Fail"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
感謝您的啓發。 objective-c似乎與我以前的語言不同,比如c#和java。 – fuzionist 2014-10-02 17:48:12
上面顯示的委託模式是在Objective-C和整個iOS SDK中使用的非常常見的設計模式。優秀的iOS開發人員熟悉它並將其用於自己的代碼中。要獲得更多有關委託的經驗,請嘗試實施和定製UITableView。 UITableView有一個委託和一個數據源協議,可以幫助你更多地瞭解這種設計模式。 – dfmuir 2014-10-02 18:09:08