Magento 2 : Selected categories are not visible in edit form

In that case you need to modify getData function.

For edit category_ids value must be an array.Suppose category_ids value save in db as comma separated that means '7,9,22'. So when you edit this value should be [7,9,22].

/**
 * Get data
 *
 * @return array
 */
public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }

    $items = $this->collection->getItems();

    foreach ($items as $item) {
        $data = $item->getData();
        $data['category_ids'] = explode(',', $data['category_ids']);
        $result['example_details'] = $data;
        $this->loadedData[$item->getId()] = $result;
    }
    return $this->loadedData;
}

In Your example_form.xml for field category_ids

Change this

<item name="formElement" xsi:type="string">select</item>

To

<item name="formElement" xsi:type="string">multiselect</item>

Make sure you are getting values for field category_ids comma separated values magento will do the rest.