Couple things that I have found that works:
1) Print out multiple copies of the TSA rules. One locked inside your hard case. One taped to the outside of your hard case, one in your wallet, one with your tickets, and one in your back pocket. Be ready to pull out the one in your back pocket and point to to specific sections when questioned.
2) DO NOT USE TSA LOCKS on your packed hard case. No one should have access to your firearm except you. If they need to see or check something, they have to page you and you have to be present to open the hard case.
3) Transport with mags empty, no mag in the grip, ammo in its original case. I also like to remove the slide from the pistol and place them in the lock box clearly separated so that you can easily tell the pistol is disassembled (therefore non-functional) via an X-ray of the case. I have found that packing the gun this way this lessens the need to have you respond to the TSA luggage screeners and open the case for them to inspect.
4) When you approach the ticket agent to check-in and give them your bags say “I need to declare an unloaded firearm in my checked baggage.” - DO NOT SAY “I have a gun.”
https://www.tsa DOT gov/travel/transporting-firearms-and-ammunition
(replace DOT with . in the link above)