Speaking to Heat magazine, the Little Britain comic said that he had watched the 'What Makes You Beautiful' group perform live on The X Factor last year.
Walliams said: "I've only met Niall from One Direction. I went to see The X Factor last year and Niall came up to me and told me that he'd been to see Matt and me in Little Britain Live when we went on tour.
"I was sitting there in the audience and they were on stage at the end of the show and I saw him pointing me out to the rest of the band, so I gave him a wave."
Walliams continued: "Then I waited until I got all the boys' attention and did this [does a "w**ker" sign with hand]. They loved it!"
Asked why he thinks One Direction are so popular, Walliams said: "It's all about hair. The girls love floppy hair. If only I'd known that when I was 16. They're great and seem really fun and likeable."
Discussing the current series of The X Factor, the 40-year-old said that he continues to watch it "religiously", revealing himself to be a "big fan" of Gary Barlow.
"I think he's amazing on it. I did wonder whether the show would work without Simon Cowell, because he's the one whose opinion we all trusted. He's generally right," he said. "But Gary is so assured and so knowledgeable about the business that he's perfect. He also looks so good. I want his stylist and nutritionist. "
"He's so sweet and his story is so moving. Coming from that bedsit to this. He's going to be doing personal appearances in regional gay clubs for the rest of his life," he said, joking: "As will I!"
The full interview with David Walliams appears in the new issue of Heat - out today.