-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[전얀] 메모장 앱 만들기 #14
base: main
Are you sure you want to change the base?
[전얀] 메모장 앱 만들기 #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "snapkit", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/SnapKit/SnapKit.git", | ||
"state" : { | ||
"revision" : "f222cbdf325885926566172f6f5f06af95473158", | ||
"version" : "5.6.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// AddMemoViewController.swift | ||
// iOS_Study_B | ||
// | ||
// Created by 정민지 on 11/15/23. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
struct MemoInformation: Identifiable { | ||
var id: ObjectIdentifier? | ||
var title: String? | ||
var content: String? | ||
} | ||
|
||
class AddMemoViewController: UIViewController { | ||
let TitleTextField: UITextField = { | ||
let textField = UITextField() | ||
textField.placeholder = "제목 입력" | ||
textField.borderStyle = .roundedRect | ||
return textField | ||
}() | ||
let ContentTextField: UITextField = { | ||
let textField = UITextField() | ||
textField.placeholder = "내용 입력" | ||
textField.borderStyle = .roundedRect | ||
return textField | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .white | ||
|
||
configureSubviews() | ||
makeConstraints() | ||
|
||
navigationItem.title = "메모 작성" | ||
setNavigationBar() | ||
} | ||
|
||
func configureSubviews() { | ||
view.addSubview(TitleTextField) | ||
view.addSubview(ContentTextField) | ||
|
||
} | ||
|
||
func makeConstraints() { | ||
TitleTextField.snp.makeConstraints{make in | ||
make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(20) | ||
make.leading.equalTo(view.safeAreaLayoutGuide.snp.leading).offset(20) | ||
make.trailing.equalTo(view.safeAreaLayoutGuide.snp.trailing).offset(-20)} | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ContentTextField.snp.makeConstraints{make in | ||
make.top.equalTo(TitleTextField.snp.bottom).offset(20) | ||
make.leading.equalTo(view.safeAreaLayoutGuide.snp.leading).offset(20) | ||
make.trailing.equalTo(view.safeAreaLayoutGuide.snp.trailing).offset(-20)} | ||
} | ||
|
||
func setNavigationBar() { | ||
let addButton = UIBarButtonItem(title: "작성하기" , style: .plain, target: self, action: #selector(addButtonTapped)) | ||
navigationItem.rightBarButtonItem = addButton | ||
} | ||
@objc func addButtonTapped() { | ||
guard let title = TitleTextField.text, let content = ContentTextField.text else { | ||
// 제목 또는 내용이 nil일 경우 처리 | ||
return | ||
} | ||
Comment on lines
+64
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제목, 내용이 없어도 메모가 작성되는 이슈가 있어요! |
||
|
||
// 입력된 값으로 Memo 객체 생성 | ||
let newMemo = MemoInformation(id: ObjectIdentifier(self), title: title, content: content) | ||
|
||
// ViewController에 대한 참조를 가져와 새로운 메모를 추가 | ||
if let viewController = navigationController?.viewControllers.first as? MainViewController { | ||
viewController.addMemo(newMemo) | ||
} | ||
|
||
self.navigationController?.popViewController(animated: true) | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변수명은 카멜 케이스 사용부탁드려요!