【问题标题】:UIButton Call in separate ClassUIButton 在单独的类中调用
【发布时间】:2016-10-08 23:25:20
【问题描述】:

我正在使用可扩展的 tableView。其中一个单元格将用于在 safari 中打开 URL 链接的按钮。按钮 IBOulet 在 WebsiteCell 类中,数据和视图控制器在 Detail View 中。

在详细视图类中,我在尝试调用显示为websiteCell.venueURL(UIButton) 的按钮时出错。错误显示“通话中的额外参数”。

这里应该用什么来代替 UIButton?

WebsiteCell 类

class WebsiteCell: UITableViewCell {



@IBAction func venueURL(sender: UIButton) {


}

详细视图类

else if indexPath.row == 3 {
        let websiteCell = tableView.dequeueReusableCellWithIdentifier("websiteCell") as! WebsiteCell

        let venueURL = venues!["URL"] as! String



        websiteCell.venueURL(UIButton){
            UIApplication.sharedApplication().openURL(NSURL(string: venueURL)!)



        }

【问题讨论】:

    标签: ios swift uibutton


    【解决方案1】:

    我会将情节提要中的按钮添加到 websiteCell 类型的原型单元格中。然后您可以将此按钮作为@IBAction 链接到您的websiteCell 类,打开URL 的代码应该放在IBAction 中。

    class WebsiteCell: UITableViewCell {
    
        var venueURL: String?
    
        @IBAction func venueURL(sender: UIButton) {
            UIApplication.sharedApplication().openURL(NSURL(string: venueURL)!)
        }
    
    }
    

    然后,您的 cellForRowAtIndexPath 方法将如下所示:

    else if indexPath.row == 3 {
    
        let websiteCell = tableView.dequeueReusableCellWithIdentifier("websiteCell") as! WebsiteCell
    
        websiteCell.venueURL = //url here
    
        return websiteCell
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多