微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 在Swift 2中实现accessoryButtonTappedForRowWithIndexPath:

我正在尝试在UITableViewController上的 Swift 2中实现accessoryButtonTappedForRowWithIndexPath:

正如我在下面解释的那样,我认为在创建revealIndicator时我遗漏了一些内容,但我不知道是什么.它来自代码,但我的目标操作不会被调用.啊!

为了以编程方式执行此操作,我的理解是我需要在返回单元格之前在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步:在单元格上添加正确的accessoryType:

cell.accessoryType = .DetaildisclosureButton

第2步:通过创建accessoryButtonTappedForRowWithIndexPath函数来点击按钮时执行操作:

override func tableView(tableView: UITableView,accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
    doSomethingWithItem(indexPath.row)
}

原文地址:https://www.jb51.cc/iOS/330791.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐