Эй, ребята, у меня самая странная ошибка в разрабатываемом приложении.
Дело в том, что у меня есть экран входа в систему с двумя текстовыми полями, которые я создаю, добавляю как подпредставления и освобождаю, все сделано в viewDidLoad.
Затем, когда пользователь вошел в систему и вышел снова, текстовые поля выглядят как обычно, но когда вызывается метод login, он считает, что текстовые поля пусты!
Я также нашел эту ошибку только на iOS 4.2.1 (8C148a)
Кроме того, в журнале отображается «Предупреждение о получении памяти. Уровень = 1», а иногда и «Уровень = 2», и это может быть связано, но я не знаю.
Кто-нибудь может мне помочь? Я совсем заблудился ...
My viewDidLoad:
userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 85, 280, 30)];
userNameTextField.returnKeyType = UIReturnKeyNext;
userNameTextField.placeholder = @"Användarnamn:";
userNameTextField.layer.cornerRadius = 8;
userNameTextField.alpha = 0.9;
userNameTextField.opaque = YES;
userNameTextField.tag = 0;
userNameTextField.backgroundColor = [UIColor whiteColor];
userNameTextField.textAlignment = UITextAlignmentCenter;
userNameTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
userNameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
userNameTextField.adjustsFontSizeToFitWidth = FALSE;
[userNameTextField addTarget:self
action:@selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 119, 280, 30)];
passwordTextField.returnKeyType = UIReturnKeyDone;
passwordTextField.placeholder = @"Lösenord:";
passwordTextField.secureTextEntry = YES;
passwordTextField.layer.cornerRadius = 8;
passwordTextField.alpha = 0.9;
passwordTextField.opaque = NO;
passwordTextField.tag = 1;
passwordTextField.backgroundColor = [UIColor whiteColor];
passwordTextField.textAlignment = UITextAlignmentCenter;
passwordTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
passwordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwordTextField.adjustsFontSizeToFitWidth = TRUE;
[passwordTextField addTarget:self
action:@selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[self.view addSubview:userNameTextField];
[self.view addSubview:passwordTextField];
userNameTextField.delegate = self;
passwordTextField.delegate = self;
[userNameTextField release];
[passwordTextField release];
Я также использую следующие методы:
-(void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];}
-(IBAction)textFieldDone:(id)sender {
[sender resignFirstResponder];}
-(BOOL)textFieldDidReturn:(UITextField *)textfield {
NSInteger nextTextFieldTag = textfield.tag + 1;
// Find next responding textfield
UIResponder *nextRespondingTextField = [textfield.superview viewWithTag:nextTextFieldTag];
if (nextRespondingTextField) {
[nextRespondingTextField becomeFirstResponder];
} else {
[self logInUser];
[textfield resignFirstResponder];
}
return NO;}
-(IBAction) logInUser {
// Popup alert
if (userNameTextField.text.length == 0 && passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Vänligen ange användarnamn och lösenord." delegate:nil cancelButtonTitle:@"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Vänligen ange lösenord." delegate:nil cancelButtonTitle:@"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (userNameTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Vänligen ange användarnamn." delegate:nil cancelButtonTitle:@"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else {
PreschoolAppDelegate *globalAppDelegate = [[UIApplication sharedApplication] delegate];
// Set global username and password
globalAppDelegate.globalUserName = @"";
globalAppDelegate.globalPassword = @"";
globalAppDelegate.globalUserName = userNameTextField.text;
globalAppDelegate.globalPassword = passwordTextField.text;
// Clear variables
globalAppDelegate.globalFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalLastname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildSurname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFullname = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChild = [[NSMutableString alloc] init];
globalAppDelegate.globalIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalChildIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChildId = [[NSString alloc] init];
globalAppDelegate.globalWipChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildIdList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalAbsenceArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalAbsenceDescription = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationDescription = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalVacationArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDates = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDates = [[NSMutableArray alloc] init];
//
// Start the fetch of the data from the rest service
//
userClient = [[GetUserListRestClient alloc] init];
[userClient getUsers:self];
[pendingLogin startAnimating];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector (checkIfConnFinished:) userInfo:nil repeats:YES];
}}