gpt4 book ai didi

ios - 在单独的类中调用 UIButton

转载 作者:行者123 更新时间:2023-11-30 13:00:21 26 4
gpt4 key购买 nike

我正在使用可扩展的 tableView。其中一个单元格将用作在 safari 中打开 URL 链接的按钮。按钮 IBOulet 位于 WebsiteCell 类中,数据和 View Controller 位于详细 View 中。

在详细信息 View 类中,我在尝试调用显示 websiteCell.venueURL(UIButton) 的按钮时出现错误。该错误显示“调用中存在额外参数”。

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

WebsiteCell 类

class WebsiteCell: UITableViewCell {



@IBAction func venueURL(sender: UIButton) {


}

详细 View 类

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)!)



}

最佳答案

我会将 Storyboard中的按钮添加到 websiteCell 类型的原型(prototype)单元中。然后,您可以将此按钮作为 @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

}

关于ios - 在单独的类中调用 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39938421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com