我有一个包含自定义UITableViewCell的UITableView,每个单元格都包含一个按钮,当按下该按钮时,应该将用户带到与该按钮所属的单元格对应的新页面。我目前已将UIButton连接到我的UITableViewCell类,并在我的cellForRowAtIndexPath方法中添加了:
let aSelector : Selector = "largeMap"
cell.MapImageButton.addTarget(self, action: aSelector, forControlEvents: UIControlEvents.TouchUpInside)
我的largeMap方法如下所示:
func largeMap(sender: UIButton!) {
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let manager = NSFileManager.defaultManager()
self.performSegueWithIdentifier("largeMapView", sender: self)
println(sender.tag.description)
largeMapView.image = UIImage(data: manager.contentsAtPath(documentsPath+"/Flight"+(sender.tag.description)+"/Map.png")!)!
}
由于这不起作用,我尝试使用我的方法:
func largeMap(sender: UIButton!) {
}
当我在设备上运行应用程序并选择其中一个按钮时,我仍然收到以下错误:
2015-01-09 09:23:46.457 FlightTracker[872:167441] -[FlightTracker.FlightsViewController largeMap]: unrecognized selector sent to instance 0x14553d7b0
2015-01-09 09:23:46.462 FlightTracker[872:167441] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FlightTracker.FlightsViewController largeMap]: unrecognized selector sent to instance 0x14553d7b0'
*** First throw call stack:
(0x185f5659c 0x1966ac0e4 0x185f5d664 0x185f5a418 0x185e5eb6c 0x18a73cd34 0x18a725e48 0x18a73c6d0 0x18a73c35c 0x18a7358b0 0x18a708fa8 0x18a9a7f58 0x18a707510 0x185f0e9ec 0x185f0dc90 0x185f0bd40 0x185e390a4 0x18efdb5a4 0x18a76e3c0 0x1000cd76c 0x1000cd7ac 0x196d1aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
我的选择器出了什么问题?
答案 0 :(得分:3)
如果您想将Button作为发件人添加到您的功能,您需要添加":"在函数名称的末尾:
像:
let aSelector : Selector = "largeMap:"