我设置了带有操作表的表格视图。但是每当介绍操作表时我都会遇到问题。
这是代码和图像的一部分。
class MoviesTableViewController: UIViewController {
@IBOutlet weak var moviesTableView: UITableView!
private let actionSheet = UIAlertController(title: "정렬방식 선택", message: "영화를 어떤 순서로 정렬할까요?", preferredStyle: .actionSheet)
private var movies: Movies?
private var api: BoxOfficeAPI?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
moviesTableView.estimatedRowHeight = moviesTableView.rowHeight
moviesTableView.rowHeight = UITableView.automaticDimension
NotificationCenter.default.addObserver(self, selector: #selector(setData(_:)), name: .MoviesNotification, object: nil)
moviesTableView.delegate = self
moviesTableView.dataSource = self
configureRefreshControl()
api = BoxOfficeAPI(with: "https://connect-boxoffice.run.goorm.io/movies?order_type=0", and: .Movies)
api?.request()
actionSheet.addAction(UIAlertAction(title: "예매율", style: .default, handler: { _ in
}))
actionSheet.addAction(UIAlertAction(title: "큐레이션", style: .default, handler: { _ in
}))
actionSheet.addAction(UIAlertAction(title: "개봉일", style: .default, handler: { _ in
}))
actionSheet.addAction(UIAlertAction(title: "취소", style: .cancel, handler: { _ in
}))
}
func configureRefreshControl() {
moviesTableView.refreshControl = UIRefreshControl()
moviesTableView.refreshControl?.addTarget(self, action: #selector(handleRefreshControl), for: .valueChanged)
}
@objc func handleRefreshControl() {
self.moviesTableView.reloadData()
DispatchQueue.main.async {
self.moviesTableView.refreshControl?.endRefreshing()
}
}
@IBAction func setOrder(_ sender: UIBarButtonItem) {
present(actionSheet, animated: true, completion: nil)
}
}
我能知道为什么会发生吗?