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.


Best way to manage probably huge photo library with iPhone SDK

1:

How make scrolling function with Interface builder on the iPhone?
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. How programatically move a UIScrollView to focus in a control above keyboard?This is super fragile, it is entirely possible this this will change inside of minor updates or bugfixes. How much of a transition is programming Java to iPhone apps?In 2.x Apple added and modified several keyboards.. Best client-side data store for iPhone web app? 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 return back info from a child to parent in a NavigationController If you want to did this you should implement your own custom numeric keyboard and pop it in and out when you need it. Do you tag your UIViews or retain them as properties?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.. return value javascript UIWebView


66 out of 100 based on 71 user ratings 226 reviews