🖥️
iOS App with Pop
UIKit Swift 5
UIKit Swift 5
  • iOS App development
  • Swift
    • Variable & Constant
    • Number & String
    • Operator
    • Array, Dictionary & Tuple
    • Enum
    • Optional
    • Function
    • Class & Struct
    • Branching
    • Loops
    • Error handler
    • Protocol
    • Extension
  • Create New Project
  • Introduction to Xcode
  • Scene-Based Life-Cycle
  • UIViewController
  • Storyboard
  • First Run
  • Display todo list
  • Basic Auto Layout
  • MVC
  • Model
  • Binding TableView
  • Binding TableViewCell
  • TableViewDelegate
  • Add navigationBar with + button
  • Add new item page
  • TextField and Switch
  • Binding action
  • Add mock item to todo list
  • What is weak?
  • Finish add item
  • Delete todo item
  • Edit todo item
  • Custom new layout
  • Adding new delegate
  • Refactor
  • Pushing edit view
  • Large navigation
  • Drag item
  • Drop item (in app)
  • Save data
  • Where to go from here?
Powered by GitBook
On this page
  • หน้าเพิ่ม Todo
  • เชื่อมกับหน้าแรกด้วย Segue

Add new item page

PreviousAdd navigationBar with + buttonNextTextField and Switch

Last updated 2 years ago

หน้าเพิ่ม Todo

หน้าเพิ่ม Todo item เราจะทำเป็นหน้าใหม่ที่เปิดขึ้นมาซ้อนหน้าแรก โดยเลื่อนจากด้านล่างมาด้านบน หน้าตาแบบนี้

ให้เราลาก ViewController ใหม่ มาจาก Object Library วางลงใน Main.storyboard

จากนั้นเนื่องจากเราจะใช้วิธีแสดงซ้อนขึ้นมาบนหน้าแรก (Modal) เราจึงต้อง Embed In Navigation Controller แบบเดียวกับหน้าแรกเพื่อให้มี หัว Title ในหน้า Add และมีที่สำหรับปุ่ม Cancel และปุ่ม Done

ลองไม่ Embed In Navigation Controller แล้วข้ามไปสร้าง Segue ตามหัวข้อถัดไปเลยจะเป็นอย่างไร และ Segue แบบ Show กับ Present Modally ต่างกันอย่างไร

ให้เราตั้งชื่อ Title เป็น Add New Item

ใส่ปุ่ม Cancel และ Done

เชื่อมกับหน้าแรกด้วย Segue

หลังจากนั้นเราจะสร้างการเชื่อมโยงด้วย Segue ให้เรากด ctrl ค้างไว้ คลิ๊กที่ปุ่ม + ในหน้าแรกลากมายัง Navigation Controller

เลือก Action Segue เป็น Present Modally ตั้ง Identifier ให้ Segue โดยคลิ๊กที่ segue ก่อนแล้วตั้ง identifier ใน Attributes Inspector เป็น openAddItemSegue (เราจะใช้ในภายหลัง)

รันแล้วลองกดปุ่ม + ในหน้าแรก

Embed In Navigation Controller