视图转到表视图,并且该表不起作用

时间:2019-05-10 21:42:43

标签: ios swift xcode

我在项目中添加了动画和表格。动画似乎叠加在桌子上,并且不起作用:( LINK 1LINK 2

let sportMenu = ["Начать тренировку","Выбрать другую","Советы по упражнениям"]


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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
    cell?.textLabel?.text = sportMenu[indexPath.row]
    return cell!


}


func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
    switch indexPath.row {
    case 0:
        performSegue(withIdentifier: "StartTraining", sender: nil)
    default:
        break
    }
}


@IBOutlet weak var animation: UIView!
@IBOutlet weak var settingsIcon: UIBarButtonItem!


let animationView = AnimationView()
let size: CGFloat = 540

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView()
    tableView.isScrollEnabled = false


    navigationController?.navigationBar.prefersLargeTitles = true
    navigationItem.largeTitleDisplayMode = .automatic

    let animation = Animation.named("Espander")
    animationView.animation = animation
    animationView.play()
    animationView.loopMode = .loop

    animationView.frame = CGRect(x: 0, y: 0, width: size, height: size)
    animationView.contentMode = .scaleAspectFit
    view.addSubview(animationView)

    animationView.translatesAutoresizingMaskIntoConstraints = false
    animationView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: -120).isActive = true
    animationView.heightAnchor.constraint(equalToConstant: size).isActive = true
    animationView.widthAnchor.constraint(equalToConstant: size).isActive = true
    animationView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true

}

1 个答案:

答案 0 :(得分:0)

我认为缺少DelegateDataSource分配。 请首先创建表格的出口。

  

@IBOutlet弱变量tblView:UITableView!

在您的ViewDidload

内部
tblView.delegate = self
tblView.dataSource = self

愿这项工作。您还可以从情节提要中分配Delegate和DataSource