Hi Gang.
Happy new years !!!
Well an annoying bug just came up. a real pain to debug.
My keyboard keeps auto dismissing it's self when you are typing.
keyboard is called by a UIAlert. This only happens after many many runs so can't seem to reproduce it.
I think it has something about releasing the UIAlert but again, can't seem to reproduce it on simulator. even after 30 calls.
here's the offending code.
Any hints on tracking it down would be appreciated.
thanks
Ian
Happy new years !!!
Well an annoying bug just came up. a real pain to debug.
My keyboard keeps auto dismissing it's self when you are typing.
keyboard is called by a UIAlert. This only happens after many many runs so can't seem to reproduce it.
I think it has something about releasing the UIAlert but again, can't seem to reproduce it on simulator. even after 30 calls.
here's the offending code.
Code:
// in HighScoreViewController.h
UIAlertView *winAlert;
....
// in HighScoreViewController.m
-(void)showWinAlert
{
NSLog(@"gameTime was:%@",userScore.gameTime);
NSMutableString *messageAlert = [[NSMutableString alloc]initWithFormat:
@"with Time: %@",userScore.gameTime];
// Testing alert //
winAlert = [[UIAlertView alloc] initWithTitle:@"New High Score!!!"
message:messageAlert
delegate:self
cancelButtonTitle:@"OK !"
otherButtonTitles:nil];
// if High Score then //
[winAlert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[winAlert textFieldAtIndex:0].keyboardAppearance = UIKeyboardAppearanceAlert;
[winAlert becomeFirstResponder];
[[winAlert textFieldAtIndex:0] setTextAlignment:UITextAlignmentCenter];
[winAlert textFieldAtIndex:0].text=@"Player Name";
[myTable reloadData];
[winAlert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"OK !"])
{
UITextField *username = [alertView textFieldAtIndex:0];
// UITextField *password = [alertView textFieldAtIndex:1];
userScore.name =(NSMutableString *)username.text;
//userScore.country =[NSMutableString stringWithFormat: @"Moon base alpha"];
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
userScore.country =(NSMutableString *)[locale displayNameForKey: NSLocaleCountryCode
value: countryCode];
NSLog(@"Username: %@\n", userScore.name);
[myHighScoreTable replaceObjectAtIndex:2 withObject:userScore];
[myHighScoreTable sortUsingDescriptors:[NSMutableArray arrayWithObject:
[NSSortDescriptor sortDescriptorWithKey:@"gameTime"
ascending:YES
selector:@selector(caseInsensitiveCompare:)]]];
NSLog(@"there are #%i",[myHighScoreTable count]);
NSLog(@"Name:%@ - Time:%@ = %i",userScore.name,userScore.gameTime,
userScore.gameTimeSeconds);
// [myHighScoreTable removeObjectAtIndex:[myHighScoreTable count]];
[myHighScoreTable removeLastObject];
NSInteger indexOfEntery = [myHighScoreTable indexOfObject:userScore];
NSLog(@"found at: %i",indexOfEntery);
[myTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
//[self.view setNeedsDisplay];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexOfEntery inSection:0];
//[yourTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
[myTable scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionTop animated:YES];
// self.winAlert = nil;
}
}
- (void)viewDidUnload
{
NSLog(@"HighScore Unloaded");
//[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showWinAlert) object:nil];
[winAlert resignFirstResponder];
self.winAlert = nil;
[winAlert release];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
//[[NSNotificationCenter defaultCenter] postNotificationName:@"hsreleased" object:nil];
}
Any hints on tracking it down would be appreciated.
thanks
Ian