ios - Swift 3.0 中 UIView 内的 UITableView

标签 ios uitableview swift3

UITableView 放入 UIView 时遇到问题。

我设置了一个委托(delegate)数据源并实现了所有方法。

这是我的 UIView 类。

@objc class ChooserView: UIView, UITableViewDelegate, UITableViewDataSource {


@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var showView: UIView!
@IBOutlet weak var tableView: UITableView!    

public class func createChooserView() -> ChooserView {

    var view: ChooserView!
    view = Bundle.main.loadNibNamed(String(describing: ChooserView.self), owner: self, options: nil)?.first as! ChooserView

    _ = MLAutolayouts.fillContainer(UIApplication.shared.keyWindow!.subviews.first!, view: view)

    //Register cell nib
    view.tableView.register(UINib(nibName: "PhoneCell", bundle: nil), forCellReuseIdentifier: "PhoneCell")

    return view
    }

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PhoneCell.self)) as! PhoneCell

    return cell
    }

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print("TAP...")
   } 
}

这就是导出

enter image description here

当运行我的应用程序时。我收到此错误

   -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fded2e772d0

记录图像。

enter image description here

任何想法...

谢谢。

最佳答案

连接数据源的IB并委托(delegate)给ChooserView而不是任何其他 View 。

只需右键单击您的表格 View ,然后 按照随附的 gif 正确连接 IB:

enter image description here

关于ios - Swift 3.0 中 UIView 内的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41986560/

相关文章:

ios - UITableview 问题的动态高度

ios - 选择时 View 从 UITableViewCell 中消失

ios - 使用Alamofire在 TableView 中操作YouTube播放列表API

ios - Xcode 4.6.2 : Variable Doesn't Show Up In Outlets

ios - 实现 'WKNavigationDelegate' 方法 'didReceiveServerRedirectForProvisionalNavigation' 方法以遵循重定向的示例

ios - 检查 CloudKit 中是否已存在记录订阅

ios - 在应用程序中将 google Plus 和 Google AppInvite 的 Pod 集成在一起

iphone - 设置 UITableView 的框架不能正常工作

ios - 如何在 iOS 中退出键盘

ios - 使 UItableview 单元格高度等于它的子 UItableview