【问题标题】:how to make @IBAction in table?如何在表格中制作@IBAction?
【发布时间】:2015-05-15 00:32:45
【问题描述】:

我写了一个应用程序来有一张桌子,当我按下按钮时它会打电话。我已经做了一张表,代码如下..

var callContent = ["Police","Hospital"]
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return callContent.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Name")
    cell.textLabel?.text = callContent[indexPath.row]
    return cell
}

还有我的调用函数

var url:NSURL = NSURL(string: "tel://0812742111")!
    UIApplication.sharedApplication().openURL(url)

现在我想从表中执行一个操作来连接我的调用函数。 各位大神可以提个建议吗?

【问题讨论】:

    标签: ios uitableview swift call


    【解决方案1】:

    听起来你想实现UITableViewDelegatedidSelectRowAtIndexPath

    Here is the Apple documentation for that class.

    【讨论】:

    • 做了之后可以做IBAction对吗?我需要插入按钮吗?
    • 您不需要 IBAction。 didSelectRowAtIndexPath 在您按下表格单元格时被调用。
    • 我是否需要一个 if else 来按下或不需要? @奥利弗
    • indexPath 会告诉你按下的是哪一个,类似于cellForRowAtIndexPath 函数。
    • 嗨@asiaandudeCom,如果这个答案已经解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
    猜你喜欢
    • 2018-11-07
    • 2014-04-25
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2010-10-13
    相关资源
    最近更新 更多