0
1

More than 3 years have passed since last update.

iOS app開発 習得日記 (3)

Posted at

(https://qiita.com/gomi_ningen/items/4e0e5bd98f08c4bcf93d)

続き

4.6.2
まで行くが、つまづく

エラーが理解できない

viewDidLoadにdelegateプロパティを設定するところ

addTaskTextField.delegete = self

ここで、Use of unresolved identifier とでる。
tableViewと同じように宣言しなければならないのはわかっているのだが、
どうすればいいのか?
接続するのか?

誰か教えてください!!

import UIKit
import Foundation

class TODOMainViewContorller: UIViewController {

    @IBOutlet weak var dismissButton: UIBarButtonItem!

   @IBOutlet weak var tableView: UITableView!

    @IBOutlet weak var textField: UITextField!

    fileprivate var tasks:[String] = ["go to school", "go back home"]

    override func viewDidLoad() {
        super.viewDidLoad()
        dismissButton.target = self
        dismissButton.action = #selector(TODOMainViewContorller.dismissButtonTapped(_ :))
        tableView.delegate = self
        tableView.dataSource = self

        addTaskTextField.delegete = self

    }

    @objc func dismissButtonTapped(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }

}

    extension TODOMainViewContorller: UITableViewDataSource {
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return tasks.count
    }
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            if let cell = tableView.dequeueReusableCell(withIdentifier: "TODOMainViewTableCell") as? TODOMainViewTableCell {
                cell.taskLabelText = tasks[indexPath.item]
                return cell
            } else {
                return UITableViewCell()
            }

        }

}

extension TODOMainViewContorller: UITableViewDelegate {

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 1
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        NSLog("selected row at: \(indexPath.item)")
    }

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

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let action = UITableViewRowAction(style: .destructive, title: "Delete") {[weak self] _,_ in self?.tasks.remove(at: indexPath.item)
            tableView.reloadData()

    }
        return[action]
}

}

extension TODOMainViewContorller: UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        if let task = textField.text, task != "" {
            tasks.append(task)
            textField.text = ""
            tableView.reloadData()
        }
        return true
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1