我尝试在Swift 2中的UITableViewController
上实现accessoryButtonTappedForRowWithIndexPath:
。
正如我在下面解释的那样,我认为在创建disclosureIndicator
时我遗漏了一些东西,但我不知道是什么。它是从代码中提取的,但我的目标操作没有被调用。
要以编程方式完成此操作,我的理解是,在返回cell
之前,需要在cellForRowAtIndexPath
中添加detailDisclosure指示符。
// Create disclosure indicator button in the cell
let disclosureIndicatorButton = UIButton(type: UIButtonType.DetailDisclosure)
disclosureIndicatorButton.addTarget(self, action: "disclosureIndicatorPressed:event:", forControlEvents: UIControlEvents.TouchUpInside)
customCell.accessoryType = .DisclosureIndicator
在我的代码中,绘制了detailDisclosure V形图案,但没有调用我分配给它的目标操作方法。
然后,我需要为按下按钮时的按钮创建一个处理程序:
func disclosureIndicatorPressed(sender: UIButton, event: UIControlEvents) {
print("disclosure button pressed")
// convert touches to CGPoint, then determine indexPath
// if indexPath != nil, then call accessoryButtonTappedForRowWithIndexPath
}
最后accessoryButtonTappedForRowWithIndexPath
包含了执行segue的代码,我可以做到。我遗漏了什么?
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/#//apple_ref/occ/intfm/UITableViewDelegate/tableView:accessoryButtonTappedForRowWithIndexPath:
1条答案
按热度按时间hwazgwia1#
不确定为什么要在代码中添加类似的显示按钮指示器。
您所寻找的是简单的两步流程-
**第1步:**在单元格中添加正确的
accessoryType
:**第2步:**通过创建
accessoryButtonTappedForRowWithIndexPath
函数,在点击按钮时执行操作: