我有以下内容:
let processURLS = processingViewController()
Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(processURLS.getURLsToSend),
userInfo: nil,
repeats: true)
当触发此事件时,我收到以下错误,我不确定为什么这不起作用
2016-11-09 14:47:00.504932 AcumenJLR [3414:905978] *终止应用 由于未捕获的异常'NSInvalidArgumentException',原因: ' - [AcumenJLR.homeViewController getURLsToSend]:无法识别的选择器 发送到实例0x100d25c60' * 第一次抛出调用堆栈:(0x1816721c0 0x1800ac55c 0x181679278 0x181676278 0x18157059c 0x18215c8f8 0x1816208f4 0x181620608 0x18161fec4 0x18161dac0 0x18154c048 0x182fd2198 0x1875372fc 0x187532034 0x100114620 0x1805305b8)libc ++ abi.dylib:终止于 NSException类型的未捕获异常
这是getURLsToSend方法
func getURLsToSend () {
//create a fetch request, telling it about the entity
let fetchRequest: NSFetchRequest<URLsToSend> = URLsToSend.fetchRequest()
let context = getContext()
do {
//Get results
let searchResults = try getContext().fetch(fetchRequest)
print ("num of results = \(searchResults.count)")
//You need to convert to NSManagedObject to use 'for' loops
for urls in searchResults as [NSManagedObject] {
//get the Key Value pairs (although there may be a better way to do that...
//print("\(urls.value(forKey: "url"))")
let currentURL = urls.value(forKey: "url")!
//print(urls.value(forKey: "url")!)
completeLoadAction(urlString: currentURL as! String) { code in
if (code == 200){
context.delete(urls)
}
}
}
} catch {
print("Error with request: \(error)")
}
答案 0 :(得分:1)
根据目标/行动模式,selector
中指定的方法必须在target
中指定的类中声明,在本例中为当前类self
。
更改target
或在self
中实施该方法。
答案 1 :(得分:-1)
你可能在方法上有一些参数,但你没有从那里发送任何价值