gpt4 book ai didi

uitableview - 在自定义 UITableViewCell 中连接 UIButton

转载 作者:可可西里 更新时间:2023-11-01 01:06:27 25 4
gpt4 key购买 nike

我有一个包含自定义 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

我的选择器有什么问题?

最佳答案

如果您想将 Button 作为 Sender 添加到您的函数中,您需要在函数名称的末尾添加一个“:”:

喜欢:

let aSelector : Selector = "largeMap:"

关于uitableview - 在自定义 UITableViewCell 中连接 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27862711/

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