imageView.contentModeでエラーになった時

まず画像を用意する
チョキは適当な画像が見当たらなかった為、ピースサイン

続いてStory boardにUIImageViewを配置する
control でviweController.swiftに繋げて、UIImage(named: “janken_goo”)と書く
let image = UIImage(named: “janken_goo”)
imageView.image = image

class ViewController: UIViewController {

    @IBOutlet weak var imageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let image = UIImage(named: "janken_goo")
        imageView.image = image
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

UIImageViewの画像サイズのままになっている。。
48x48pixなんだけどな。
それと、今日、本屋で立ち読みした本には、画像はAssets.xcassestsに置くと書いてあったが。。swift書くまえにいきなりつまづいた。

imageView.contentMode で画像の縦横サイズを指定出来るらしい。

override func viewDidLoad() {
        super.viewDidLoad()
        let image = UIImage(named: "janken_goo")
        imageView.image = image
        imageView.contentMode = UIViewContentMode.Center
        self.view.addSubview(imageView)
        // Do any additional setup after loading the view, typically from a nib.
    }

UIViewContentMode.Centerでerror, build出来ない。
なに???

いろいろなサイトを横断して、appleのdeveloper siteのuiviewcontentmodeを見てみる
https://developer.apple.com/documentation/uikit/uiviewcontentmode

case center
The option to center the content in the view’s bounds, keeping the proportions the same.

なに? centerは小文字?
imageView.contentMode = UIViewContentMode.centerで再度build

override func viewDidLoad() {
        super.viewDidLoad()
        let image = UIImage(named: "janken_goo")
        imageView.image = image
        imageView.contentMode = UIViewContentMode.center
        self.view.addSubview(imageView)
        // Do any additional setup after loading the view, typically from a nib.
    }

おおおお、ファイヤー
iOS開発で初めてちょっと仕事した!

IndexPathSelectedRow

 @IBAction func unwindToMemoList(sender: UIStoryboardSegue)
    {
        guard let sourceVC = sender.source as? memoViewController, let memo = sourceVC.memo else {
            return
        }
        if let selectedIndexPath = self.tableView.indexPathForSelectedRow {
            self.memos[selectedIndexPath.row] = memo
        } else {
            self.memos.append(memo)
        }
        self.tableView.reloadData()
    }

tableView.reloadDataでtableviewを表示
うーむ、windowsでudacityのiosコースのコードをなぞっていたのは全く時間の無駄だったな。

tableViewController からeditTextに値をわたす

override func viewDidLoad() {
        super.viewDidLoad()
        self.saveButton.isEnabled = false
        if let memo = self.memo {
            self.memoTextField.text = memo
        }
        // Do any additional setup after loading the view.
    }

キャンセルを実行する

 @IBAction func cancel(_ sender: Any) {
        if self.presentingViewController is UINavigationController {
            self.dismiss(animated: true, completion: nil)
        } else {
            self.navigationController?.popViewController(animated: true)
        }
    }

スワイプしてtableviewを削除

tableviewcontrollerのコメントをはずす

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            // Delete the row from the data source
            self.memos.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .fade)
        } else if editingStyle == .insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }

おおお、すげー
機能ありすぎて整理出来んな

メモを追加

var memo: String?
    @IBOutlet weak var memoTextField: UITextField!
    @IBOutlet weak var saveButton: UIBarButtonItem!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.saveButton.isEnabled = false
        // Do any additional setup after loading the view.
    }

    @IBAction func memoTextFieldChanged(_ sender: Any) {
        let memo = self.memoTextField.text ?? ""
        self.saveButton.isEnabled = !memo.isEmpty
    }
    
    @IBAction func cancel(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let button = sender as? UIBarButtonItem, button === self.saveButton else{
            return
        }
        self.memo = self.memoTextField.text ?? ""
    }

oh my goodness
i dont understand whats going on

Navigation Controllerとは

Navigation Controllerとは、ページ上部にナビゲーションバーを表示し、複数画面を階層的に移動できるようにする部品。ナビゲーションバーや前画面に戻るためのボタンが自動表示

TableViewでtitleと詳細

var memos = [
        ["title":"t1", "detail":"d1"],
        ["title":"t2", "detail":"d2"],
        ["title":"t3", "detail":"d3"]
    ]

 override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.memos.count
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MemoTableViewCell", for: indexPath)

        // Configure the cell...
        cell.textLabel?.text = self.memos[indexPath.row]["title"]
        cell.detailTextLabel?.text = self.memos[indexPath.row]["detail"]

        return cell
    }

indexPath.section

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MemoTableViewCell", for: indexPath)

        // Configure the cell...
        cell.textLabel?.text = self.memos[indexPath.section][indexPath.row]

        return cell
    }