From Sahih Bukhari (Hadith 4184):
Narrated Nafi`:Ibn `Umar assumed Ihram and said, "If something should intervene between me and the Ka`ba, then I will do what the Prophet (ﷺ) did when the Quraish infidels intervened between him and (the Ka`ba). Then Ibn `Umar recited: "You have indeed in Allah's Messenger (ﷺ) A good example to follow
Reference: Bukhari 4184