To diagnose focus issues when shooting through the viewfinder as opposed to shooting live view:
- Change AF/MF setting to AF
- Turn off focus limiter in the lens, if any (24mm f2.8 does not have a focus limiter; long telephotos do)
- Adjust the camera to use all focus points if shooting through the viewfinder
- If the camera is equipped with "stop focus search" / "continue focus search" option when focus cannot be achieved, set it to "continue focus search"
The start focusing on things that are farther away than the minimum focus distance of the lens! Note that focus requires enough contrast. By having multiple focus points, chances that you have enough contrast are better.
Then after this you can test each focus point individually by separately selecting the used focus point.
By doing these tests, chances are you'll diagnose the focus issue: lens or camera. For example if some focus point does not work, it's the camera. If no focus point works, it may be the camera or a lens (try a different lens to make sure).
Try adjusting the aperture and taking a picture as well (preferably in manual focus mode so that not obtaining focus won't stop you from taking pictures). If you can't do these or if the aperture setting has no effect on exposure, the camera-lens contacts may be faulty and require cleaning.
Do note if the lens is searching for focus at all. Usually when you can't achieve focus, the lens may be hunting for focus and you should be able to note this in the viewfinder.
It may be the case there is some fault somewhere and the camera confirms focus only if it's already in focus. This may explain why you could focus on your pants.