*Sets up soapbox and stands on top of it*
It happens, but there are things you can do to make it happen less often:
1. Don't use say-do-see patter where you say what you are going to do, do it and tell the audience to see what happened. If your patter is nothing more than narrating what is happening, the audience will focus on what you are doing. Audiences are trained to think that the game of magic is that you perform tricks and they figure out how it is done. If all they have to focus on is what you are doing, they will see what you are doing. To get over this, you need to engage the audience in a different way. That is where meaningful patter comes into play.
2. Don't perform in a "look at me" style which makes it a challenge to the audience. Too often magic is presented as "look at what I can do (and you can't)." if you put yourself up above your audience, they will try to take you down. Make magic fun. See how Dani DaOrtiz performs (which is so strongly influenced by Tamariz). He is not above the audience but right there alongside them having fun. Involve the audience as equals, not as people to be fooled (because who wants to be a fool?).
3. Perfect practice makes perfect. Practice until you can do it correctly with your eyes closed. I've gotten to the point in my cups and balls routine that I don't realize I'm doing the final loads - so I'm surprised to when they are there! The sleights should be automatic and should be able to be done while you are talking (see #1 above for what you should be saying).
4. Design the effect or routine properly. Utilize natural misdirection and off beats to perform sleights, have the moves happen well before the audience think the magic happens and make every movement seem natural. Perform without magician's guilt which is the tension and involuntary reactions like looking at your hands, pausing your speech or changing your tempo when you perform a sleight.
5. Don't do this:
Patter options: If someone says "I know how you did that," pull out some quip like "Well, that's not very impressive- I know it too" or "Yes, it's magic. Very good." Or "Really? Well, everyone give a round of applause to (insert name of meddler here)"- then hand them a deck of cards, sit in front of them and stare.
Those reactions will alienate the rest of the audience (making you seem like a jerk) and will give the heckler what they want - attention. Best to just say, "I suppose you could do it that way..." and then move on in your performance. Remember, not everyone who guesses a method is a heckler - some people are wired that way and some people are trained to think that is their job. Your job is to structure your performance so that they don't care about the method.