Indeed, the adequate number of iterations over Grover's iterator depends on the number of solutions. Various methods have been proposed over the years to overcome this difficulty when the number of solutions is unknown, without giving up on the computational advantage that Grover's algorithm offers. I am going to cover 2 of those.
Method 1 - a stochastic iterative stepping process:
in section 4 of the paper "Tight bounds on quantum searching" by Boyer et al., there exists a description of the following method - given that $N$ is the dimension of the search-space and $t$ is the number of solutions, pick a step-size variable $1 < \lambda < \frac{4}{3}$, and set an upper-bound variable $m = 1$. Then initialize an iterative process consisting of the following steps:
- Increase $m$ by a factor of $\lambda$, i.e: $m = \lambda m$. If $\lambda m > \sqrt{N}$ then set $m = \sqrt{N}$.
- Pick randomly $j$ number of iterations, while $j$ is a natural number smaller than $m$, i.e $\{ j < m\ |\ j \in \mathbb{N} \}$.
- Execute Grover's algorithm with $j$ iterations and measure an outcome $i$.
- Verify that $i$ is indeed a solution (that's classically efficient and easy). If $i$ is a solution - done. If not - repeat.
Note that this process reveals one solution at a time, and should be initialized and repeated a sufficient number of times to reveal all solutions (depending on the size of $N$). It is noted in the paper that the time complexity of this process is $O\left(\sqrt{\frac{N}{t}}\right)$.
Method 2 - a dynamic circuit while loop:
This approach is kinda innovative and involves a dynamic circuit implementation (i.e non-unitary conditional operations are being used). There is a description of a proposed method in the paper - "A quantum while loop for amplitude amplification". I won't go into a detailed description but the overall idea is to exploit a weak measurements technique (recently explained in this QCSE post) to find out whether a solution is obtained in each Grover's iteration. It is done by allocating a "probe" qubit where $|1\rangle$ is written into where a solution is obtained. The probe qubit is measured in each iteration. If the outcome of the measurement is $1$, a measurement over the input qubits that spans the search-space is executed, and we're done, If the outcome of the measurement is $0$, the next iteration over Grover's iterator is executed. by measuring the probe qubit a partial collapsing of the system's quantum state occurs, as explained in the linked QCSE post. I would say that is the overall idea of this approach in a nutshell, for a detailed explanation look into the linked paper.
There is an open-source Qiskit-based package that I built, which synthesizes quantum circuits for satisfiability problems while exploiting Grover's algorithm. It uses versions of the above methods in cases where the number of solutions isn't known. It is called SAT Circuits Engine and there exists a pretty detailed demo of its proposed features in a demonstration notebook. It might help you better understand the nature of Grover's algorithm and the described methods above.