Button not removed with removedFromSuperVire


Button not removed with removedFromSuperVire



I'm using the trick to put a custom button for the numeric keyboard.

But I can't remove the button after use it, so in regular keyboard appear on top of the view.

This is how I add it:

- (void)keyboardShow:(NSValue *)v  {     if (isKeyboardNumeric) {     	// create custom button     	UIButton *doneButton = [[UIButton alloc] init];     	//doneButton.buttonType = UIButtonTypeCustom;     	doneButton.frame = CGRectMake(0, 163, 106, 53);     	doneButton.adjustsImageWhenHighlighted = NO;     	if ([[[UIDevice currentDevice] systemVersion] hasPrefix:@"3"]) {     		[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];     		[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];     	} else {             		[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];     		[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];     	}     	[doneButton addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventTouchUpInside];     	doneButton.tag = 99;     	// locate keyboard view     	UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];     	UIView* keyboard;     	for(int i=0; i<[tempWindow.subviews count]; i++) {     		keyboard = [tempWindow.subviews objectAtIndex:i];     		// keyboard view found; add the custom button to it     		if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)     			[keyboard addSubview:doneButton];     	}     } } 

And this how I remove it:

- (void)keyboardHide {     UIView *btn;     UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];     UIView* keyboard;     for(int i=0; i<[tempWindow.subviews count]; i++) {     	keyboard = [tempWindow.subviews objectAtIndex:i];     	// keyboard view found; add the custom button to it     	if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {     		for (btn in keyboard.subviews) {     			if (btn.tag==99) {     				[btn removeFromSuperview];     				[btn release];     				break;     			}     		}     	}     }	     [self setupButtons]; } 

Both methods get called correctly, and in the debugger I confirm that is called

[btn removeFromSuperview] 

But anyway, the button remain.

I try to put the code to remove it just before the if (isKeyboardNumeric) call but nothing.


Using an existing C++ engine on the iPhone

1:

How do I set these break points in ~/.gdbinit?
This is exactly the sort of thing Apple tells you not to did it, and clear you know it for the reason this you are attempting to guard yourself by checking OS revisions, etc. Is Macro Better Than UIColor for Setting RGB Color?This is super fragile, it is entirely possible this this will change inside of minor updates or bugfixes. Facebook iphone connectionIn 2.x Apple added and modified several keyboards.. Is anyone testing Mono-Touch? [closed] The fact you can't receive sensible behavior is not surprising, who knows what Apple is doing inside the the keyboard view, they could be retagging or doing custom drawing caching off screen images of the view to increase drawing efficiency.. How to intercept text from the keyboard and format it before it show in the cell? If you want to did this you should implement your own custom numeric keyboard and pop it in and out when you need it. Getting an iPhone app's product name at runtime?Probably not the answer you want to hear, although it will probably end up being a lot simpler than hacking around in your views, and a lot less likely to cause problems for your users.. declaring global variables in iPhone project


66 out of 100 based on 31 user ratings 356 reviews