swift - 从 UIButton 更改后的 UIBarButtonItem 错误
问题描述
我遇到了这个问题,我得到了一些示例代码,我试图用UIBarButtonItems
.
谁能说出我的代码中的问题是什么,我不知道普通的按钮和UIBarButtonItems
不同的按钮。
所以我将 showPopup 中的发件人从 更改为UIView
,UIButton
但现在出现另一个错误(请参见下面的屏幕截图)
很抱歉发布代码的图像,但没有发布代码。继承人的shopPopup
功能:
func showPopup(sender: UIButton, mode:String, text:String="", row:Int=0) {
if !(mode=="edit" || mode=="new") { return }
let popVC = storyboard?.instantiateViewController(withIdentifier: "NewPopup") as! NewPopupVC
popVC.mode = mode
popVC.currentText = text
popVC.currentRow = row
popVC.modalPresentationStyle = .popover
let popPC = popVC.popoverPresentationController!
popPC.sourceView = sender
popPC.sourceRect = sender.bounds
popPC.delegate = self
popPC.permittedArrowDirections = [.up, .down]
present(popVC, animated:true, completion: nil)
}
继承人 func addButton
。这就是第一个错误所在。
@IBAction func addButton(_ sender: UIBarButtonItem) {
showPopup(sender: sender, mode: "new")
}
这是发生第二个错误的部分。
@objc func handleLongPress(_ gesture: UILongPressGestureRecognizer) {
if gesture.state != .began { return }
let pt = gesture.location(in: tableView)
if let path = tableView.indexPathForRow(at: pt),
let row = (path as NSIndexPath?)?.row,
let cell = tableView.cellForRow(at: path)
{
showPopup(sender: cell,
mode: "edit",
text: todoList[row],
row: row)
}
}
更新了最后出现的错误的屏幕截图。 截屏
解决方案
你必须这样做
func showPopup(sender: UIButton, mode: String, text:String = "", row:Int = 0)
sender
从更改UIView
为UIButton
推荐阅读
- python-3.x - 根据键填充 NaN 值
- css - 如何让 @apply 在 TailwindCSS 中工作?
- javascript - React:在 Array Map 中渲染额外的组件
- networking - 副本集中所有 pod 之间的消息传递
- php - 通过 PHP 将产品从 XML 导入 CSV
- osgi - 在 wcm.io 的 AEM Mocks 中取消注册服务
- arduino - 如何使用arduino阻止LED在距离以上点亮?
- apache - 使用 .htaccess 将网站语言突变重定向到不同域上的等效语言
- sql-server - SQL Server 链接服务器错误“合作伙伴事务管理器已禁用其对远程/网络事务的支持。”
- c - C:在单独的函数中使用 realloc() 不会改变数组大小