-
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
[숲] 6주차 실습 #20
base: main
Are you sure you want to change the base?
[숲] 6주차 실습 #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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,111 @@ | ||
// | ||
// AddButtonViewController.swift | ||
// MemoClone | ||
// | ||
// Created by 박현수 on 2023/11/20. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
protocol MemoAddDelegate: AnyObject { | ||
func didAddMemo(title: String, content: String) | ||
} | ||
|
||
class AddMemoViewController: UIViewController, UITextViewDelegate { | ||
|
||
weak var delegate: MemoAddDelegate? | ||
|
||
@objc func registerMemo() { | ||
if (titleText.textColor == .lightGray || contentText.textColor == .gray || titleText.text.isEmpty || contentText.text.isEmpty) { | ||
print("잘못된 제목 또는 내용입니다.") | ||
return | ||
} | ||
delegate?.didAddMemo(title: titleText.text, content: contentText.text) | ||
_ = self.navigationController?.popViewController(animated: true) | ||
} | ||
|
||
var titleText: UITextView = { | ||
let text = UITextView() | ||
text.layer.cornerRadius = 5 | ||
text.layer.borderWidth = 0.5 | ||
text.text = "제목 입력" | ||
text.textColor = UIColor.lightGray | ||
text.tag = 1 | ||
return text | ||
}() | ||
|
||
var contentText: UITextView = { | ||
let text = UITextView() | ||
text.layer.cornerRadius = 5 | ||
text.layer.borderWidth = 0.5 | ||
text.text = "내용 입력" | ||
text.textColor = UIColor.gray | ||
text.tag = 2 | ||
return text | ||
}() | ||
|
||
func textViewDidBeginEditing(_ textView: UITextView) { | ||
if textView.tag == 1 { | ||
if textView.textColor == UIColor.lightGray { | ||
textView.text = nil | ||
textView.textColor = UIColor.black | ||
} | ||
} | ||
else if textView.tag == 2 { | ||
if textView.textColor == UIColor.gray { | ||
textView.text = nil | ||
textView.textColor = UIColor.black | ||
} | ||
} | ||
} | ||
|
||
func configureSubviews() { | ||
view.addSubview(titleText) | ||
view.addSubview(contentText) | ||
} | ||
|
||
func makeConstraints() { | ||
titleText.snp.makeConstraints { make in | ||
make.top.equalTo(view.safeAreaLayoutGuide).offset(50) | ||
make.leading.equalToSuperview().inset(50) | ||
make.trailing.equalToSuperview().inset(50) | ||
Comment on lines
+71
to
+72
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.
|
||
make.height.equalTo(50) | ||
} | ||
contentText.snp.makeConstraints { make in | ||
make.top.equalTo(view.safeAreaLayoutGuide).offset(150) | ||
make.leading.equalToSuperview().inset(50) | ||
make.trailing.equalToSuperview().inset(50) | ||
make.height.equalTo(50) | ||
} | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let rightButton = UIBarButtonItem(title: "작성하기", style: .plain, target: self, action: #selector(registerMemo)) | ||
|
||
titleText.delegate = self | ||
contentText.delegate = self | ||
configureSubviews() | ||
makeConstraints() | ||
|
||
view.backgroundColor = .white | ||
navigationItem.title = "메모 작성" | ||
navigationItem.rightBarButtonItem = rightButton | ||
|
||
// Do any additional setup after loading the view. | ||
} | ||
|
||
|
||
/* | ||
// MARK: - Navigation | ||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
// Get the new view controller using segue.destination. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// DetailViewController.swift | ||
// MemoClone | ||
// | ||
// Created by 박현수 on 2023/11/20. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
protocol ModifyMainViewDelegate: AnyObject { | ||
func modifyArray(title: String, content: String, cellIndex: Int) | ||
} | ||
|
||
class DetailViewController: UIViewController, ModifyMemoDelegate { | ||
|
||
var modifyMainViewDelegate: ModifyMainViewDelegate? | ||
|
||
func memoModified(index: Int, cellTitle: String, cellContent: String) { | ||
modifyMainViewDelegate?.modifyArray(title: cellTitle, content: cellContent, cellIndex: index) | ||
isModified = true | ||
} | ||
|
||
var cellIndex: Int = 0 | ||
var isModified: Bool = false | ||
|
||
var titleLabel: UILabel = { | ||
let title = UILabel() | ||
title.font = .boldSystemFont(ofSize: 20) | ||
return title | ||
}() | ||
|
||
var contentLabel: UILabel = { | ||
let content = UILabel() | ||
content.font = .systemFont(ofSize: 15) | ||
return content | ||
}() | ||
|
||
@objc func modifyMemo() { | ||
let modifyView = ModifyMemoViewController() | ||
modifyView.modifyMemoDelegate = self | ||
modifyView.titleText.text = titleLabel.text | ||
modifyView.contentText.text = contentLabel.text | ||
modifyView.cellIndex = cellIndex | ||
_ = self.navigationController?.pushViewController(modifyView, animated: true) | ||
} | ||
|
||
func configureSubViews() { | ||
view.addSubview(titleLabel) | ||
view.addSubview(contentLabel) | ||
} | ||
|
||
func makeConstraints() { | ||
titleLabel.snp.makeConstraints { make in | ||
make.leading.equalTo(view.safeAreaLayoutGuide).inset(20) | ||
make.trailing.equalTo(view.safeAreaLayoutGuide).inset(20) | ||
make.top.equalTo(view.safeAreaLayoutGuide).offset(10) | ||
} | ||
contentLabel.snp.makeConstraints { make in | ||
make.leading.equalTo(view.safeAreaLayoutGuide).inset(20) | ||
make.trailing.equalTo(view.safeAreaLayoutGuide).inset(20) | ||
make.top.equalTo(titleLabel.snp.bottom).offset(10) | ||
} | ||
} | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .white | ||
|
||
let rightButton = UIBarButtonItem(title: "수정하기", style: .plain, target: self, action: #selector(modifyMemo)) | ||
navigationItem.title = "메모 상세" | ||
navigationItem.rightBarButtonItem = rightButton | ||
|
||
configureSubViews() | ||
makeConstraints() | ||
// Do any additional setup after loading the view. | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
if isModified == true { | ||
_ = self.navigationController?.popViewController(animated: false) | ||
Comment on lines
+80
to
+81
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. 수정이 됐을 때 바로 홈으로 이동하는 것보다는 |
||
} | ||
} | ||
|
||
|
||
/* | ||
// MARK: - Navigation | ||
|
||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
// Get the new view controller using segue.destination. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// MemoTableViewCell.swift | ||
// MemoClone | ||
// | ||
// Created by 박현수 on 2023/11/20. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
class MemoTableViewCell: UITableViewCell { | ||
|
||
static let identifier = "MemoTableViewCell" | ||
|
||
var titleLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = .boldSystemFont(ofSize: 15) | ||
return label | ||
}() | ||
|
||
var contentLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = .systemFont(ofSize: 10) | ||
return label | ||
}() | ||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
configureSubviews() | ||
makeConstraints() | ||
} | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func configureSubviews() { | ||
contentView.addSubview(titleLabel) | ||
contentView.addSubview(contentLabel) | ||
} | ||
|
||
func makeConstraints() { | ||
titleLabel.snp.makeConstraints { make in | ||
make.top.leading.trailing.equalTo(contentView).inset(15) | ||
} | ||
contentLabel.snp.makeConstraints { make in | ||
make.top.equalTo(titleLabel.snp.bottom).offset(5) | ||
make.leading.trailing.bottom.equalTo(contentView).inset(15) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// ModifyMemoViewController.swift | ||
// MemoClone | ||
// | ||
// Created by 박현수 on 2023/11/20. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
protocol ModifyMemoDelegate{ | ||
func memoModified(index: Int, cellTitle: String, cellContent: String) | ||
} | ||
|
||
class ModifyMemoViewController: UIViewController { | ||
|
||
var modifyMemoDelegate: ModifyMemoDelegate? | ||
|
||
var cellIndex: Int = 0 | ||
|
||
var titleText: UITextView = { | ||
let text = UITextView() | ||
text.layer.cornerRadius = 5 | ||
text.layer.borderWidth = 0.5 | ||
return text | ||
}() | ||
|
||
var contentText: UITextView = { | ||
let text = UITextView() | ||
text.layer.cornerRadius = 5 | ||
text.layer.borderWidth = 0.5 | ||
text.textColor = UIColor.gray | ||
return text | ||
}() | ||
|
||
@objc func modifyMemo() { | ||
modifyMemoDelegate?.memoModified(index: cellIndex, cellTitle: titleText.text, cellContent: contentText.text) | ||
navigationController?.popViewController(animated: true) | ||
} | ||
|
||
func configureSubviews() { | ||
view.addSubview(titleText) | ||
view.addSubview(contentText) | ||
} | ||
|
||
func makeConstraints() { | ||
titleText.snp.makeConstraints { make in | ||
make.top.equalTo(view.safeAreaLayoutGuide).offset(50) | ||
make.leading.equalToSuperview().inset(50) | ||
make.trailing.equalToSuperview().inset(50) | ||
make.height.equalTo(50) | ||
} | ||
contentText.snp.makeConstraints { make in | ||
make.top.equalTo(view.safeAreaLayoutGuide).offset(150) | ||
make.leading.equalToSuperview().inset(50) | ||
make.trailing.equalToSuperview().inset(50) | ||
make.height.equalTo(50) | ||
} | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
/*let rightButton = UIBarButtonItem(title: "수정하기", style: .plain, target: self, action: #selector(modifyMemo)) | ||
|
||
titleText.delegate = self | ||
contentText.delegate = self*/ | ||
configureSubviews() | ||
makeConstraints() | ||
|
||
let rightButton = UIBarButtonItem(title: "수정하기", style: .plain, target: self, action: #selector(modifyMemo)) | ||
|
||
view.backgroundColor = .white | ||
navigationItem.title = "메모 수정" | ||
navigationItem.rightBarButtonItem = rightButton | ||
//navigationItem.rightBarButtonItem = rightButton | ||
// Do any additional setup after loading the view. | ||
} | ||
} | ||
|
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.
내용이 입력되지 않았을 때의 분기처리 하신 거 너무 좋습니다!!
그런데 로그만 띄우면 사용자는 알 수 없으니까
와 같은 코드를 구현하면 더 좋을 것 같아요!