Without an atmosphere to create a blast wave, a nuke in space wouldn't have much impact on an asteroid's trajectory. Although the energy is impressive, the momentum-transferring mass is extremely tiny (when compared, say, to a rocket booster). Moreover, since the explosion is spherical, only half the energy is directed in the asteroid's direction, and much of that is tangential to the direction you want to push it.
If you bury the nuke and try to blow the asteroid apart, then you're trading the devil you know for the devil you don't know. It's impossible to determine how many pieces will result from such an exercise and what their trajectories would be. You could make things far worse.
It's been argued that blasting an asteroid into smaller chunks would "soften" its blow. And to some extent, this is certainly true. Large thunderstorms release many times the energy of the first atom bombs, but because this energy release is spread over a large area over a large amount of time, the damage is most often negligible.
But everything is a matter of degree. Our planet will happily endure the energy of a puny atom bomb spread over a large area and not even notice. But if an impactor has the kinetic energy sufficient to end civilization, then civilization will end, no matter how that energy is distributed.
My preferred method of deflecting Apophis is to splatter it with buckets of white paint. Painting it white will make it subject to photon pressure from the sun, slightly altering its course. Over time, this could be enough to save us. Of course, this method works only if you have lots of time (as we do with Apophis), and only if pushing it further from the sun is the direction it needs to go to prevent disaster.