The University of Barcelona has some agreements with multiple organizations that help foreign students to find a place to live.
For instance, it has a settlement with the BCU (Barcelona University Centre). It is an organization whose aim is to help foreign university students with all non-academic aspects of life. For example, it helps the students to find the most suitable accommodation according to their needs.
Moreover, the University of Barcelona itself provides a number of services for temporary-stay students, such as sports facilities or housing. If you want more information, follow this link.
If none of those options fits you, you can search a place to live through an online marketplace for booking student accommodation called Uniplaces.