Yes, coffee and many other drinks and foods can interfere with your body absorbing iron. But it does not seem to be the caffeine that is the problem. It is related to another ingredient in coffee called phenolic acid. Drinking coffee and taking iron at the same time can decrease how much iron you absorb by as much as 40%.
But you cant just substitute tea or hot chocolate for coffee. In fact, cocoa and certain teas (especially black tea and peppermint tea) are even more potent iron absorption blockers. These drinks can inhibit your bodys ability to absorb iron by over 70%. And adding milk to coffee or tea does not make a difference.
As you suggested, waiting two hours after drinking coffee before taking your iron pill makes sense. But you dont need to stop drinking coffee completely.
To enhance how much iron you absorb, make sure to get plenty of vitamin C in your diet. For people who are anemic and iron deficient, I often recommend that they take their iron pill with 250 mg of vitamin C.