【问题标题】:How to control TableView in View in Swift如何在 Swift 中的 View 中控制 TableView
【发布时间】:2018-09-08 03:17:03
【问题描述】:
  1. 我做了一个单视图项目。
  2. 我在视图中添加了一个UIView 对象
  3. 我在视图中添加了一个UITableView 对象。
  4. 我制作了一个TableViewController Cocoa Touch 文件来自动创建单元格。
  5. 为了链接TableViewControllerUITableView,我尝试使用Identity Inspector 将表视图类更改为TableViewController,但没有成功。没有一个班级出现。

问题一:为什么不能更改表格视图类?

问题 2:如何同时控制视图和表格视图?

【问题讨论】:

    标签: swift uitableview tableview


    【解决方案1】:

    1) 您无法更改 tableView 的类,因为该对象是 UITableView 类型的,而您正尝试将其设置为 UITableViewController

    类型的类

    2)要同时控制View和TableView,可以设置outlet。

    class YourViewController: UIViewController, UITableViewDelegate, UITableViewDatasource {
        // Connect the outlets to storyboard's YourViewController UI
        @IBOutlet var tableView: UITableView!
        @IBOutlet var yourView: UIView!
    
        override func viewDidLoad() {
          super.viewDidLoad()
    
          // Set delegate and datasource and implement the delegate methods
          self.tableView.dataSource = self
          self.tableView.delegate = self
    
          // Handle the view properties for yourView here
          self.yourView.backgroundColor = UIColor.red
        }
    }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-15
      • 2013-02-14
      • 2020-01-02
      • 2018-06-01
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 2017-06-29
      相关资源
      最近更新 更多