Let's start with some definitions. A heckler is someone who is intent on ruining your performance by doing things that draw attention to themselves and by doing so take the audience's attention off of you. A spectatator that guesses at methods or tries to figure things out isn't a heckler.
For a heckler, the issue is control. The best defense is to be is to be interesting, engaging and entertaining. A typical heckler won't even try to draw attention to themselves when they know they can win. In table hopping contexts, acknowlege the alpha male (it isn't hard to see who that is in a group) and perform for them. This placated their ego because you are placing them in control and giving them a stake in the outcome - they've agreed to let you perform so they have an interest everyone being entertained. In other situations, you need to control the social dynamic so that the audience will support you over the heckler (think of the audience telling the heckler to be quiet so they can see you perform). If you are performing in school, it is a losing battle because perceived social status will trump magical skill. That is, if the heckler has a higher perceived social status, then then the audience will side with them.
As for people who try to figure things out, there are two types. The first type thinks that is what magic is about - you perform, they try to guess. There may be a lot of causes for that including your presentation, TV shows exposing magic, Penn and Teller's Fool Us and other magician's performances. The second type, well that is their personalities - they are the engineers and scientists of the world who think that everything in life needs to be explained - they know there is a method and they need to come up with a hypothesis.
Fortunately, the solution is the same for both types of figure-outers. Presentation. Let me elaborate about say-do-see patter. That is where you say what you are going to do, you do it and tell the audience to see what happens. The focus is on what you are doing and what happens as a result. Is it any wonder that the audience focuses on what you are doing and what happens and then tries to figure out HOW what you are doing results in what happened? There is nothing else for them to focus on. If you just show them what happens, then the natural question is HOW was it done. Presentation needs to engage the audience on an intellectual, emotional and personal level. If they are engaged with what you are saying, the effect becomes intertwined with your presentation. So rather than the spectator thinking "I picked a card, put it in the deck and the magician pulled it out of his pocket" the spectator is thinking, "he was talking about how memories are as real as we want them to be and even though I put my card in the deck, he told me to try to remember that I put it in his pocket. Then, I pulled the card I remembered out of his shirt pocket."
The strong presentation forces them to focus on two things at once. Try watching a magic trick you havent seen before without any volume while listening to a random unrelated TED lecture without watching the video. Can you describe both the trick and the lecture in detail? I didn't think so. If you involve the spectator by giving them tasks to do it is even harder. Try watching the video, listening to the lecture and counting how many coins are in a handful of coins.
If you layer that presentation with strong effects, then you shouldn't have a problem. One idea is self working effects - get Scarne on Card Tricks or Card College Light. There is nothing to figure out. Another idea is to structure the routines in a way that leaves subtle hints that one method is the way only to dispell that method (see Tamariz's The Magic Way for a better explanation of this concept). Another idea is to structure the effect and presentation so that the spectator figures out the ending a moment before you are about to reveal it - it makes them want to see you succeed because then they are right in figuring out the plot. They will be telling people, "I figured out what was going to happen before he turned over the deck showing the cards all sorted by suit and in order" rather than "I figured out that he did ... to get the cards in order."
But large tigers work well too.