Reputation: 2205
This is the flow of my app. 1st view -> 2nd View -> 3rd View
On 3rd view, when I click on any row of tableView one UIView gets displayed, which has one textField which accepts only numbers. For this I have implemented UIKeyboardWillShowNotification and displayed a UIButton for 'dot' button on the down-left corner of keyboard (For this I have created two images and sets that image to UIButton object).
My problem is, After using this custom keyboard(for 2-3 times), when I redirect form 3rd view to 1st View, This UIButton (with dot image) is appearing on 1st view. I have used default keyboard at there but this image not getting away.
While moving from 3rd view to 1st view, I m removing Observer for the keyboard notification which I have registered earlier & also I m checking wether,
if ([dotButton retainCount] > 0) {
[dotButton release];
dotButton = nil;
}
I have allocated dot button only once in viewDidLoad. I m using popToRootViewController method to go back to 1st view from 3rd view.
I dont want to display this dot button on my 1st view. How can I do this.
Upvotes: 0
Views: 493
Reputation: 823
Follow this steps 1) First make the doneButton an instance varible of your class, this will help u maintain the reference to the button 2) Add this code at the beginning of ur keyboardWillShow:(NSNotification *)note method
if(dotButton){
[dotButton removeFromSuperview];
dotButton = nil;
}
and one more thing implement UIKeyboardWillHideNotification method with NSNotificationCenter and perfrom step 2 over there.
Upvotes: 1
Reputation: 84308
I assume when you created the dotButton, you are calling addSubview:
to put it on the screen.
When you want to remove it, you need to remove by calling [dotButton removeFromSuperview]
. If you just release it, it will still be retained by the view that is containing it.
Finally, you should NEVER be calling retainCount
unless you are debugging something. I've been writing Objective-C code for years and I have NEVER used retainCount
, even when I was doing weird runtime stuff.
The rule is simple. If you need an object to stick around, you call retain. When you are done with it, you call release. If somebody else has retained it that's none of your business.
Upvotes: 1