         tableView.bounces = false
     }
 
-    private func updateFrame() {
-        guard let textFieldFrame = textField?.frame else {
-            return
-        }
-
-        let height = CGFloat(elements.count) * rowHeight
-        frame = CGRect(x: textFieldFrame.origin.x, y: textFieldFrame.origin.y + textFieldFrame.height, width: textFieldFrame.width, height: height > maximumHeight ? maximumHeight : height)
-        tableView.frame = CGRect(origin: .zero, size: frame.size)
+    private func setupConstraints() {
+        guard let textField = textField else {
+            assertionFailure("Sanity check")
+            return
+        }
+
+        tableView.removeConstraints(tableView.constraints)
+        removeConstraints(self.constraints)
+
+        tableView.translatesAutoresizingMaskIntoConstraints = false
+        translatesAutoresizingMaskIntoConstraints = false
+
+        heightConstraint = heightAnchor.constraint(equalToConstant: 0)
+
+        let constraints = [
+            tableView.leadingAnchor.constraint(equalTo: leadingAnchor),
+            tableView.trailingAnchor.constraint(equalTo: trailingAnchor),
+            tableView.topAnchor.constraint(equalTo: topAnchor),
+            tableView.bottomAnchor.constraint(equalTo: bottomAnchor),
+            leadingAnchor.constraint(equalTo: textField.leadingAnchor),
+            trailingAnchor.constraint(equalTo: textField.trailingAnchor),
+            topAnchor.constraint(equalTo: textField.bottomAnchor),
+            heightConstraint!
+        ]
+
+        NSLayoutConstraint.activate(constraints)
     }
 
     @objc private func textFieldEditingChanged() {

    fileprivate var elements = [String]() {
        didSet {
            tableView.reloadData()
            updateFrame()
        }
    }


    }

    @objc private func textFieldEditingEnded() {
        height = 0
    }
}

