Skip to content

Commit

Permalink
feat: ViewModel Binding (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed Jun 4, 2024
1 parent 66e6208 commit e58a0d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ extension AnswerViewController: UITableViewDelegate, UITableViewDataSource {

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// TODO: 화면 전환 코드 작성
let viewController = SolvedViewController()
viewController.titleText = "오늘 푼 퀴즈"
viewController.question = questions[indexPath.row].question
viewController.answer = questions[indexPath.row].answer[1]
self.navigationController?.pushViewController(viewController, animated: true)
let viewModel = SolvedViewModel(networkService: QuestionsNetworkService(), questionId: indexPath.row + 1)
let solvedViewController = SolvedViewController()
solvedViewController.viewModel = viewModel
self.navigationController?.pushViewController(solvedViewController, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import Then
import SnapKit

final class SolvedViewController: UIViewController {
var titleText = ""
var question = "모집인원 0명"
var answer = "1~9명" {
didSet{
answerView.set(title: question, des: answer)
}
}
var viewModel = SolvedViewModel(networkService: QuestionsNetworkService(), questionId: 0)

var isShared = false {
didSet {
setShareView()
Expand Down Expand Up @@ -59,7 +54,7 @@ final class SolvedViewController: UIViewController {
$0.textAlignment = .center
}

private let sharedView = UIView().then {
private var sharedView = UIView().then {
$0.backgroundColor = .doBlack
}

Expand All @@ -72,9 +67,19 @@ final class SolvedViewController: UIViewController {

setUI()
addTarget()
// Do any additional setup after loading the view.
bindVM()
}

private func bindVM() {
viewModel.onUpdate = { [weak self] in
guard let self = self else { return }
// UI 업데이트
self.sharedView = SharedInstaView(title: self.viewModel.questionTitle,
description: self.viewModel.answerText)
self.descriptionLabel.text = self.viewModel.questionDescription
}
}


private func setUI() {
view.backgroundColor = .doBlack
Expand Down Expand Up @@ -168,21 +173,22 @@ final class SolvedViewController: UIViewController {

func addTarget () {
sharedButton.addTarget(self, action: #selector(instagramButtonTapped), for: .touchUpInside)
backButton.addTarget(self, action: #selector(button), for: .touchUpInside)
backButton.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside)
}
func bindData() {
titleLabel.text = titleText
}

@objc func button() {
}


extension SolvedViewController {
@objc
func backButtonTapped() {
self.navigationController?.popViewController(animated: true)
}

@objc func instagramButtonTapped() {
@objc
func instagramButtonTapped() {
isShared.toggle()
setShareView()
if let storyShareURL = URL(string: "instagram-stories://share?source_application=" + "955820726285983") {
if let storyShareURL = URL(string: "instagram-stories://share?source_application=" ) {

if UIApplication.shared.canOpenURL(storyShareURL) {
let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
Expand All @@ -209,11 +215,9 @@ final class SolvedViewController: UIViewController {
UIApplication.shared.open(storyShareURL, options: [:], completionHandler: nil)
} else {
let url = URL(string: "https://apps.apple.com/kr/app/instagram/id389801252")!
print("엥?")
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}

}

0 comments on commit e58a0d9

Please sign in to comment.