Done Button Issues
- July 21st, 2010
- Posted in Code . Technology
- By Wayfarer
- Write comment
I made a quick video here:
Which sums up the issue nicely. Basically, the notifications which we create in one view affect the entire app, regardless of view. This means the Done button will appear in all the views, and all the keyboards no matter what.
Edit:
After looking around, I found that if you are running a multiview application and don’t want to have Done Buttons appearing all over the place, you can stop the notifications by adding this:
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Did you add the fix in the view where you used the modified keyboard? For me this fix did not work if I did that.
Basically I have a CustomTextField class which I add the custom button and it is used in one view of the app only. But in all views it does appear when the keyboard is brought up.
Thank you
@Shankar
That’s weird, as it worked for me just as I’ve said. I would have to see more of the code to know for sure, but do some trouble shooting around. Make sure you are adding the Notifications in the same way they do in the tutorial (the updated one, for iOS 4). After that, make sure that code I have is being called with some NSLog Statements. If it is, and you are adding the Notifications in the same way, well, it’s certainly odd. Play around with it and see if you can fix it. I suggest reading this and see if it helps at all.
The above worked great to remove the button from subsequent fields. One issue however….in a tab bar application once the user leaves the view that is using the done button code and then comes back to it, the buttons are gone. any fix for this?
You are probably running the code which adds the notifications in
loadVieworviewDidLoadmethods. However, I’m pretty sure these only load once (or in cases of memory, twice). If you want the code which adds the “done” button to run everytime, then you should add the Notification code to the viewWillAppear method of the UIViewController. That code will run everytime the view controller will “appear”, so your notifications will be added when it appears, and then removed when it disappears, so they only show up in that particular view. Hopefully this helps!