Wiring bathroom exhaust
One cable will be the feeder (hot and neutral) and one cable will go to the switch. The one that ran all the time will be your supply the other the cable to the switch. 
Turn the breaker off and verify it is off.
Tie the white on the cable that made it run all the time to the white on the fan. The black on the fan goes to the black on the cable that did nothing, the black on the cable that made it run all the time to the white that did nothing.  Now wrap some black tape on that white wire connected to the black. 
To do everything correctly the white wire at the switch should have some tape also. 
Turn the breaker on and now the switch should work .
This is a switch leg the white is always hot and should be reidentified as a hot, I said traps but tape or fingernail polish, paint any color but white green or gray would be code compliant.