gpt4 book ai didi

ios - +[UIView onBackgroundRequest :]: unrecognized selector sent to class

转载 作者:行者123 更新时间:2023-11-29 01:35:54 25 4
gpt4 key购买 nike

部署目标:8.4 swift :2.0

我有一个 UIViewController 类,它有一个 UITableView 和一个 UIView 因为它是 tableHeaderView。 UIViewController 类有一个 UINotification 监听器,用作 tableHedearView 的 UIView 调度一个 UINotification。

我的 UIViewController 类相当简单。

StartViewController(UIViewController):

class StartViewController: UIViewController, UINavigationControllerDelegate
{
@IBOutlet weak var tblContents: UITableView!

override func viewDidLoad()
{
super.viewDidLoad()

// table header view
let headerView = StartTableHeaderView(frame: CGRectMake(0, 0, tblContents.bounds.width, self.view.frame.height*0.3))
tblContents.tableHeaderView = headerView

// adds notification listener
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onBackgroundRequested:", name: "changeBackground", object: nil)
}

func onBackgroundRequested(notification:NSNotification)
{
let uiImagePicker = UIImagePickerController()
uiImagePicker.delegate = self
uiImagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

self.presentViewController(uiImagePicker, animated: true, completion: nil)
}
}

extension StartViewController: UIImagePickerControllerDelegate
{
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
...
}
}

StartTableHeaderView(UIView):

class StartTableHeaderView: UIView
{
...

@IBAction func onBackgroundRequest(sender: AnyObject)
{
NSNotificationCenter.defaultCenter().postNotificationName("changeBackground", object: nil)
}
}

在运行时,每当方法 (onBackgroundRequest) 在 StartTableHeaderView 中点击按钮时触发并分派(dispatch) UINotification,我会遇到以下错误:

2015-10-06 17:31:00.738 Elmo[1838:55864] +[UIView onBackgroundRequest:]: unrecognized selector sent to class 0x3272d90 2015-10-06 17:31:00.745 Elmo[1838:55864] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIView onBackgroundRequest:]: unrecognized selector sent to class 0x3272d90'

最佳答案

StartTableHeaderView 类中调用 onBackgroundRequest: 的按钮上的操作是如何设置的?您是在使用 Interface Builder 还是在代码中进行操作?如果在代码中,您可以发布吗?

我认为您可能没有像您想象的那样发布通知。在 StartTableHeaderView onBackgroundRequest: 中放置一个断点,看看它是否曾经被触发。

错误告诉您未找到 onBackgroundRequest:,而不是 onBackgroundRequested:

关于ios - +[UIView onBackgroundRequest :]: unrecognized selector sent to class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32969798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com