0
我有下面的代碼顯示根據結果警報:我怎樣才能提高以下代碼:如何改進Objective-C中的以下代碼?
-(IBAction)saveSettings:(id)sender
{ UIAlertView中*警報=零;
username = self.usernameTextField.text;
token = self.passwordTextField.text;
// validate the username and token
if(![self isValid])
{
// show alert that it is not valid
alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Invalid User Name or Password" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
return;
}
BOOL isSynched = [self syncSettings];
if(!isSynched)
{
alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error Syncing Settings" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Settings has been Synced Syncing" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
}
}
我想我實例提醒過很多次,看起來有點重複!