无法识别的选择器发送到 UITableView 内的实例
Unrecognized selector sent to instance inside UITableView
我有一个带有自定义单元格的 UITableViewController。我 "do not want" 识别 selected 单元格,但在 TableView 中识别 selected 标签本身。与 Instagram 类似,当我 select 用户时,它应该转到用户页面,而如果我 select 评论,它会推送到另一个评论 VC,这一切都发生在同一个单元格中。
我从这个 中学到了如何添加手势识别器,但是它让我崩溃了。
016-02-10 17:53:20.490 SocialMe[1395:476081] -[SocialMe.LatestPostViewController didSelectUserLabel]: unrecognized selector sent to instance 0x13deac830
2016-02-10 17:53:20.495 SocialMe[1395:476081] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SocialMe.LatestPostViewController didSelectUserLabel]: unrecognized selector sent to instance 0x13deac830'
*** First throw call stack:
(0x18267d900 0x181cebf80 0x18268461c 0x1826815b8 0x18258568c 0x1878f0dbc 0x1875145b8 0x1873a29b0 0x1878f23bc 0x187361b58 0x18735e8dc 0x1873a0820 0x18739fe1c 0x1873704cc 0x18736e794 0x182634efc 0x182634990 0x182632690 0x182561680 0x183a70088 0x1873d8d90 0x100077794 0x1821028b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
我的代码如下
class LatestPostViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Latest Post"
self.refreshControl?.beginRefreshing()
GetLatestPost()
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel")
self.tableView.addGestureRecognizer(userLabelRecognizer)
self.refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
}
func didSelectUserLabel(recognizer: UITapGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}
将您的代码更新为:
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel:")
self.tableView.addGestureRecognizer(userLabelRecognizer)
如果你使用类似 didSelectUserLabel
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel")
你需要像这样实现
func didSelectUserLabel()
{
}
如果你使用类似 didSelectUserLabel:
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel:")
你需要像这样实现
func didSelectUserLabel(recognizer: UITapGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}
我有一个带有自定义单元格的 UITableViewController。我 "do not want" 识别 selected 单元格,但在 TableView 中识别 selected 标签本身。与 Instagram 类似,当我 select 用户时,它应该转到用户页面,而如果我 select 评论,它会推送到另一个评论 VC,这一切都发生在同一个单元格中。
我从这个
016-02-10 17:53:20.490 SocialMe[1395:476081] -[SocialMe.LatestPostViewController didSelectUserLabel]: unrecognized selector sent to instance 0x13deac830
2016-02-10 17:53:20.495 SocialMe[1395:476081] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SocialMe.LatestPostViewController didSelectUserLabel]: unrecognized selector sent to instance 0x13deac830'
*** First throw call stack:
(0x18267d900 0x181cebf80 0x18268461c 0x1826815b8 0x18258568c 0x1878f0dbc 0x1875145b8 0x1873a29b0 0x1878f23bc 0x187361b58 0x18735e8dc 0x1873a0820 0x18739fe1c 0x1873704cc 0x18736e794 0x182634efc 0x182634990 0x182632690 0x182561680 0x183a70088 0x1873d8d90 0x100077794 0x1821028b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
我的代码如下
class LatestPostViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Latest Post"
self.refreshControl?.beginRefreshing()
GetLatestPost()
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel")
self.tableView.addGestureRecognizer(userLabelRecognizer)
self.refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
}
func didSelectUserLabel(recognizer: UITapGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}
将您的代码更新为:
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel:")
self.tableView.addGestureRecognizer(userLabelRecognizer)
如果你使用类似 didSelectUserLabel
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel")
你需要像这样实现
func didSelectUserLabel()
{
}
如果你使用类似 didSelectUserLabel:
let userLabelRecognizer = UITapGestureRecognizer(target: self, action: "didSelectUserLabel:")
你需要像这样实现
func didSelectUserLabel(recognizer: UITapGestureRecognizer) {
if recognizer.state == UIGestureRecognizerState.Ended {
let swipeLocation = recognizer.locationInView(self.tableView)
if let swipedIndexPath = tableView.indexPathForRowAtPoint(swipeLocation) {
if let swipedCell = self.tableView.cellForRowAtIndexPath(swipedIndexPath) {
// Swipe happened. Do stuff!
}
}
}
}
}