# I've wrote that code using UIAlertController, what I should change to make it works with UIViewController?

**URL:** <https://forums.swift.org/t/ive-wrote-that-code-using-uialertcontroller-what-i-should-change-to-make-it-works-with-uiviewcontroller/59091>\
**Category:** Core Libraries\
**Tags:** uikit, swiftui\
**Created:** [July 20, 2022, 11:34am UTC](https://forums.swift.org/t/ive-wrote-that-code-using-uialertcontroller-what-i-should-change-to-make-it-works-with-uiviewcontroller/59091 "2022-07-20T11:34:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArtemenkoDany](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/artemenkodany/32/24422_2.png) [@ArtemenkoDany](https://forums.swift.org/u/ArtemenkoDany)\
**Post date:** [July 20, 2022, 11:34am UTC](https://forums.swift.org/t/ive-wrote-that-code-using-uialertcontroller-what-i-should-change-to-make-it-works-with-uiviewcontroller/59091/1 "2022-07-20T11:34:11Z")

</div>

Here is my code:

```swift
override func viewDidLoad() {
        
      super.viewDidLoad()
      view.backgroundColor = .white
        
      view.addSubview(tableView)
      tableView.dataSource = self
      Preformatted texttableView.delegate = self
        
    } 
}

```

```swift
extension SecondViewController: TableViewCellDelegate{
    func tableViewCellDidTapItem(with viewModel: TileCollectionViewCellModel) {
        let alert = UIAlertController(title: viewModel.name,
                                      message: "",
                                      preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Dismis",
                                      style: .cancel,
                                      handler: nil))
        present(alert, animated: true)
    }
}

```

```swift
protocol TableViewCellDelegate: AnyObject {

func tableViewCellDidTapItem(with viewModel: TileCollectionViewCellModel)
}

```

```
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    collectionView.deselectItem(at: indexPath, animated: true)
    let viewModel = viewModels[indexPath.row]
    
    delegatee?.tableViewCellDidTapItem(with: viewModel)
}

```
