We study the cosmic evolution of the magnetic fields of a large sample of spiral galaxies in a cosmologically representative volume by employing a semi-analytic galaxy formation model and numerical dynamo solver in tandem. We start by deriving time- and radius-dependent galaxy properties using the galform galaxy formation model, which are then fed into the nonlinear mean-field dynamo equations. These are solved to give the large-scale (mean) field as a function of time and galactocentric radius for a thin disc, assuming axial symmetry. A simple prescription for the evolution of the small-scale (random) magnetic field component is also adopted. We find that, while most massive galaxies are predicted to have large-scale magnetic fields at redshift z=0, a significant fraction of them are expected to contain negligible large-scale field. Our model indicates that, for most of the galaxies containing large-scale magnetic fields today, the mean-field dynamo becomes active at z<3. We compute the radial profiles of pitch angle, and find broad agreement with observational data for nearby galaxies.