【发布时间】:2020-08-10 19:47:41
【问题描述】:
我正在尝试向我的 viewController 添加一个搜索栏(使用 IBAction 方法),但它没有显示出来。我错过了什么吗?
import UIKit
class SongrequestViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
var tableView = UITableView()
var searchBar = UISearchBar()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
tableView = UITableView(frame: CGRect(x: 10, y: 200, width: 370, height:400))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.dataSource = self
tableView.delegate = self
self.view.addSubview(tableView)
searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50))
searchBar.searchBarStyle = UISearchBar.Style.prominent
searchBar.placeholder = "Search for your song here..."
searchBar.sizeToFit()
searchBar.isTranslucent = false
searchBar.delegate = self
self.view.addSubview(searchBar)
}
tableView 显示出来了,但搜索栏没有显示出来。
【问题讨论】:
标签: ios swift ibaction programmatically-created