为什么我的UISwipeGestureRecognizer上出现此错误?

时间:2017-12-28 12:14:51

标签: ios swift uitableview uigesturerecognizer

我的自定义类单元管理器中的UISwipeGestureRecognizer出现此错误

enter image description here

它在我的主要UITableViewController类中工作...我在ViewDidLoad中创建了一个新实例:

   let updateClass = updateCell()
   updateClass.swiper()

我不太确定但是在这个thread上,我应该使用lazy var来解决问题,但它不会改变任何东西。我该怎么办 ?为什么我得到这个错误?

感谢您的帮助!

3 个答案:

答案 0 :(得分:2)

当您像创建updateClass的实例一样,系统将不会从Storyboard(或Xib)加载视图。这是nil错误的原因。

要从故事板加载表格视图单元格,您可以使用

let identifier = ... // the reusable identifier defined for this cell in storyboard

let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! updateClass

此外,您无法在viewDidLoad中调用此代码。您需要实现UITableViewDataSource接口

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // load and return your cell 
}

也许这对你来说是一个很棒的教程 https://www.raywenderlich.com/77974/making-a-gesture-driven-to-do-list-app-like-clear-in-swift-part-1

答案 1 :(得分:0)

如果你的网点没问题且rightView没有在任何地方写过,那么请确保你在主线程上调用swiper()

 DispatchQueue.main.async {
    // your code here
 }

尝试像这样调用它。如果没有同步线程,那么就会发生这种疯狂的行为。

答案 2 :(得分:-2)

可能是你的右视图是零。检查您的插座连接

相关问题