我到处都看过这个,并试图缩小我的搜索范围。如何使静态单元格显示“保留建议”执行我当前在代码中执行的操作。
if child.tag == 'SLOT':
for slot, index in child.items():
for attribute in child:
print('Slot Number =', index, ', Tag:', attribute.tag, ', Value:', attribute.text)
else:
print('Tag:', child.tag, ', Text', child.text)
此插座将单元格连接到我的视图控制器文件
@IBOutlet weak var Suggestion: UITableViewCell!
这是我试图让它执行的代码,所以我可以判断它是否正常工作。
修改 这是我实施的当前代码
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 2 && indexPath.row == 0 {
print("pressed")
}
答案 0 :(得分:2)
仅从您的屏幕截图中我希望您想要比较indexPath.section == 1
,而不是indexPath.section == 2
。
import UIKit
class AccountViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.view.backgroundColor = .clear
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 0 {
print("pressed")
}
}
}
答案 1 :(得分:1)
由于部分从0开始,所以在计算或比较部分时总是必须从0开始。因此,这就是你想要做的:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 0 {
print("pressed")
}