【问题标题】:How to get particular row button title in UITableView button click in swift如何在 UITableView 按钮中快速获取特定的行按钮标题
【发布时间】:2018-08-02 06:36:51
【问题描述】:

为学校创建时间表,使用 UITableView 实现设计

2天6个周期,周期是动态的,可以显示n个数字。

我的代码:

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dayArr.count-1
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell:PeriodCell = tableView.dequeueReusableCell(withIdentifier: "PeriodCell") as! PeriodCell
    cell.selectionStyle = .none
    tableView.separatorStyle = .none

    var x: Int = 2
    for i in 0 ..< periodArr.count
    {
            let btn: UIButton = UIButton(frame: CGRect(x: x, y: 0, width: 110, height: 45))
            btn.backgroundColor = UIColor.clear
            btn.setTitle("Select", for: .normal)
            btn.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
            btn.tag = indexPath.row
            btn.layer.cornerRadius = 5
            btn.layer.borderWidth = 1
            btn.layer.borderColor = UIColor.lightGray.cgColor
            btn.setTitleColor(UIColor.black, for: .normal)
            cell.contentView.addSubview(btn)
            x = x + 115
    }

    return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 50
}

我的按钮点击动作:

@objc func buttonAction(sender: UIButton!) {
        let btnsendtag: UIButton = sender
        print("btnsendtag",btnsendtag.tag)
        sender.setTitle("Tamil",for: .normal)
        for i in 0 ..< periodArr.count
        {
            print("btnsendtag",btnsendtag.tag)
            if let buttonTitle = btnsendtag.title(for: .normal)
            {
                print("buttonTitle",buttonTitle)
            }
        }
    }

我的问题: 1.我想得到每个按钮的标题。星期一和星期二分开作为数组分开并发送到 webservices [或] 获取所有按钮标题并将其以逗号分开发送到 webservices 。 [句点是动态的,它可以显示 n 个数字] 想要获取所有标题。仅显示 6 天。

  1. 如何识别选择了哪个按钮、添加了哪个按钮值以及没有选择的按钮希望将空标题发送到 Web 服务。如何识别。

如何编写按钮点击动作的代码。请帮助我,我从一个星期开始就在这方面苦苦挣扎。提前致谢。

【问题讨论】:

    标签: ios swift uitableview uibutton


    【解决方案1】:

    您可以使用标题项目概念轻松地将其存档在集合视图中,以便在表格视图中获得您所要求的这种类型的东西。

    【讨论】:

    • 你知道如何在collectionview中实现吗,请提供任何示例源
    • 请分享您的邮件ID,我将分享演示代码。
    • saravananesec@gmail.com
    • 你好?\
    • 是的,请在 10 分钟后检查您的邮件 ID。
    猜你喜欢
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2011-11-22
    相关资源
    最近更新 更多