Возможно, используйте while и используйте try и catch. Потому что, когда вы вводите символ вместо номера, ваша программа будет сбой.
public class StoreToArray
{
Scanner input = new Scanner(System.in);
ArrayList<Integer> al = new ArrayList<Integer>();
public static void main(String args [])
{
//Access method using object reference
StoreToArray t = new StoreToArray();
t.readFromTerminal();
}
public void readFromTerminal() {
System.out.println("Read lines, please enter some other character to stop.");
int check=0;
do{
try {
check = input.nextInt();
if(check != 0)
al.add(check);
}
catch(InputMismatchException e)
{
System.out.println("Failed to convert to int.");
check = 0;
}
}while(check != 0);
for (int i : al) {
System.out.println(i);
}
}
}
Я думаю, что было бы лучше сделать это наоборот, имея UICollectionView в качестве родителя и UITableView в качестве дочернего. Поскольку первый более гибкий и настраиваемый.
В любом случае для вашего случая, я думаю, вам нужно взглянуть на две вещи:
1- Чтобы лучше контролировать размер ячейки, вы можете использовать эту функцию для UICollectionView:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
// The desired size based on the value at that row (the name for example)
if objects[indexPath.row].name == "some condition" {
return CGSize(width: 150, height: 50)
}
else {
return CGSize(width: UIScreen.main.bounds.width, height: 75)
}
}
2- Значения инспектора размера для UICollectionView и UITableView (в одном из них может быть дополнительный интервал)