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

斯威夫特 – 从一个单元格中的按钮发出嘘声

我有一个附加到TableViewCell类的自定义单元格,我在该自定义单元格中有一个按钮,我想要乳清我按下它会分割到另一个视图控制器的按钮,但是:

performSegueWithIdentifier(identifier: String,sender: AnyObject?)

功能无法识别,如何解决

编辑:

解决方法

-performSegueWithIdentifier:方法在UIViewController中声明.所以你不能只在UITableViewCell子类中调用它.

在-tableView:cellForRowAtIndexpath:方法中创建单元格时,可以向该按钮添加操作.然后你可以在该action方法调用-performSegueWithIdentifier:方法.这是假设我们在UITableViewController子类中的示例:

func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as UITableViewCell

    cell.button.addTarget(self,action: "someAction",forControlEvents: .TouchUpInside)

    return cell
}

这是行动方法

func someAction() {
    self.performSegueWithIdentifier("movetoView",sender: self)
}

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

相关推荐