4INCENSE / geha-sajang-iOS

1 stars 0 forks source link

[캘린더] 캘린더 탭 #21

Closed dev-Lena closed 3 years ago

dev-Lena commented 3 years ago

캘린더 탭 만들기

UI

Process

Storyboard

FSCalendarScopeMonth -> 당일 방 예약 현황 목록 화면으로 연결 FSCalendarScopeWeek -> 당일 게스트하우스 서비스 이용 목록 화면으로 연결 하단 테이블뷰 위에 static cell이 아닌 버튼으로 두어도 괜찮을 듯


하단 테이블 뷰 -> 당일 예약 게스트 목록 화면으로 연결

하단 화면 구성

Segmented Control - 당일 예약 게스트 목록 & 당일 게스트하우스 서비스 이용 목록 & 당일 방 예약 현황 목록

dev-Lena commented 3 years ago

객체

TableView에 PanGesture를 등록해 UITableViewDelegate에서 didSelect 처리하지 않고 UIGestureRecognizerDelegate에서 처리 UITableViewDelegate의 didSelect 메소드는 static cell 선택 시 호출

정리하기

PanGestureRecognizer.require(toFail:) 메소드 self.tableView.contentOffset.y <= -self.tableView.contentInset.top 의 의미

dev-Lena commented 3 years ago

변경 전

변경 후

두 버튼

각 화면은 추후 재사용을 위해 xib로 만들기 -> 일단 화면을 띄우는 것 까지. 화면 구현은 이후 (참고할 강의: Demystifying Views in iOS - raywenderlich)

-> 일단 여기까지 구현 + 구조 설계해서 이슈로 남겨놓고 예약 CRUD 화면 구현시작하기

dev-Lena commented 3 years ago

를 참고하여서 Delegate를 만들어 처리하려고 시도하였음.

protocol DailyTableViewCellDelegate {
     presentViewController(_ tableViewCell: UITableViewCell, viewController: UIViewController)
}

class TransitionButtonsRowTableViewCell: UITableViewCell {
    weak var delegate: DailyTableViewCellDelegate!

    @IBAction func bookingStatusButtonTapped(_ sender: Any) {
        let roomBookingStatusViewController = RoomBookingStatusViewController.loadFromNib()
        self.delegate?.presentViewController(self, viewController: roomBookingStatusViewController)
    }

    @IBAction func serviceStatusButtonTapped(_ sender: Any) {
       let serviceUsingStatusViewController = ServiceUsingStatusViewController.loadFromNib()
        self.delegate?.presentViewController(self, viewController: serviceUsingStatusViewController)
    }
}

extension CalendarViewController: DailyTableViewCellDelegate {
    presentViewController(_ tableViewCell: UITableViewCell, viewController: UIViewController) {
        self.present(viewController, animated: true, completion: nil)
    }

class DailyTableViewDataSource: NSObject, UITableViewDataSource {

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == TableViewIndexPath.firstSection {
            let cell = tableView.dequeueReusableCell(withIdentifier: CalendarCellName.BookingStatusButtonsCell)!
            //TODO: 이곳에서 cell의 delegate로 CalendarViewController를 지정해주어야 함
            return cell
        } 
        // ... 이하 생략
        }
    }

위와 같은 방법으로 TabelViewCell 안에있는 Button이 눌렸을 때 두 개의 버튼 중 어떤 버튼이 눌리냐에 따라서 CalendarViewController에서 알맞는 화면이 present하도록 해주고 싶었으나

TableViewDataSource에 TODO에 적어놓았다시피 이곳에서 delegate를 지정해줘야 하는데 TableViewDataSource가 ViewController를 알고 있는 것은 부자연스러움. 적절하지 않음.

-> 그래서 NotificationCenter로 post를 보내는 방법으로 수정함.