【发布时间】:2018-08-02 06:36:51
【问题描述】:
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 天。
- 如何识别选择了哪个按钮、添加了哪个按钮值以及没有选择的按钮希望将空标题发送到 Web 服务。如何识别。
如何编写按钮点击动作的代码。请帮助我,我从一个星期开始就在这方面苦苦挣扎。提前致谢。
【问题讨论】:
标签: ios swift uitableview uibutton