OC/swift tableViewCell自定义按钮点击push多次

之前用OC自定义UITableVeiwCell 上面的Button的时候 ,当点击Button 的时候也出现过这个问题 ,即 点击buttonpush 3次 或者多次到同一个页面,当时的解决方法是 在UITableViewCell ​的prepareForReuse() 方法里面 将 button 置 nil ,

例如  自定义的button 名字是  deleteButton

void  prepareForReuse()

{

self.deleteButton = nil​

}

这样就可以解决多次push问题.

现在发现在Swift里面用这个方法无法解决,说明swift 更加严谨了,更注重规范性

最后找到解决方法是这样的

先遵守UINavigationControllerDelegate​协议 ,然后成为代理

self.navigationControlelr.delegate =  self​

// 记录push标志

var ​isPushing = false

//重写协议方法

// MARK:UINavigationControllerDelegate

func navigationController(_navigationController: UINavigationController, didShowviewController: UIViewController, animated: Bool){

   self.pushing = false

}

然后再你需要push 的地方判断

if self.pushing{

   return   //被拦截

} else {  // push 控制器​

  self.pushing = true

  self.navigationController!.pushViewController(viewController,animated: true)

}​

这样就可以解决了,有什么问题欢迎留言。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容