Can't show alert from UIRow's onSelect handler

What I’m trying to achieve: present the user with a list of strings to choose from, until they click ok. Then process the selection and give some feedback in an alert. Everything works ok, but the alert just pops up for a brief moment and disappears again without waiting for any user interaction.
What am I doing wrong?


async function info(m) {
  let alert = new Alert();
    alert.message = m;
    let ix = await alert.present();
}

let select = new UITable();
  let row = new UITableRow();
  let count = 0;
  
  [1,2].forEach(f => {
    let row =new UITableRow();
    row.dismissOnSelect = false;
    row.addText("" + f);
    row.onSelect = () => {
      count++;
    }
    select.addRow(row);
  })
  row = new UITableRow()
  let button = row.addButton("ok");
  button.dismissOnTap = true;
  button.onTap = () => {
    info("" + count)
  }
  select.addRow(row)
  await select.present();

1 Like

Try changing

button.dismissOnTap = true;

to

button.dismissOnTap = false;
1 Like

Thanks a lot. That solves the problem of the not-waiting alert. But how would one dismiss the UITable now?

If you want it to close and then display the alert, you can put the alert after the closure. That way you avoid the previous issue of the disappearing alert (as it is no longer tied to the tables presentation), and still get the information output after the button press and before the script completes.

let button = row.addButton("ok");
  button.dismissOnTap = true;
  button.onTap = () => {
//    info("" + count)
  }
  select.addRow(row)
  await select.present();
  info("" + count);

Exactly. Thanks a bunch!