@@ -10,17 +10,31 @@ import UIKit
1010import SnapKit
1111import MapKit
1212
13- // MARK: - Pin Detail Main View Controller
13+
14+ // MARK: - Pin Detail Main ViewController
1415final class PinDetailViewController : UIViewController {
1516
17+ private var pinTableView = UITableView ( frame: . zero, style: . grouped)
18+ private var pinEntity : PinEntity
19+
20+ init ( _ entity: PinEntity ) {
21+ self . pinEntity = entity
22+
23+ super. init ( nibName: nil , bundle: nil )
24+ }
25+
26+ required init ? ( coder: NSCoder ) {
27+ fatalError ( " init(coder:) has not been implemented " )
28+ }
29+
30+
1631 // 더미 리뷰 데이터
1732 private lazy var datasource : [ ReviewEntity ] = [
1833 ReviewEntity ( id: UUID ( ) , pinID: UUID ( ) , date: Date ( ) , description: " 리뷰1 " ) ,
1934 ReviewEntity ( id: UUID ( ) , pinID: UUID ( ) , date: Date ( ) , description: " 리뷰2 " ) ,
2035 ReviewEntity ( id: UUID ( ) , pinID: UUID ( ) , date: Date ( ) , description: " 리뷰3 " )
2136 ]
2237
23- public var pinTableView : UITableView !
2438
2539 // MARK: - VIewDidLoad
2640 override func viewDidLoad( ) {
@@ -37,17 +51,19 @@ final class PinDetailViewController: UIViewController {
3751 // 지도 뷰
3852 public lazy var mapView : MKMapView = {
3953 let map = MKMapView ( )
54+ let lat = pinEntity. latitude
55+ let long = pinEntity. longitude
4056
41- let center = CLLocationCoordinate2D ( latitude: 37.7749 , longitude: - 122.4194 ) // San Francisco, CA
57+ let center = CLLocationCoordinate2D ( latitude: lat , longitude: long ) // San Francisco, CA
4258 let region = MKCoordinateRegion ( center: center, span: MKCoordinateSpan ( latitudeDelta: 0.05 , longitudeDelta: 0.05 ) )
4359
4460 map. setRegion ( region, animated: true )
4561 map. showsUserLocation = true
4662
4763 let annotation = MKPointAnnotation ( )
48- annotation. coordinate = CLLocationCoordinate2D ( latitude: 37.7749 , longitude: - 122.4194 ) // San Francisco, CA
49- annotation. title = " San Francisco "
50- annotation. subtitle = " CA "
64+ annotation. coordinate = CLLocationCoordinate2D ( latitude: lat , longitude: long ) // San Francisco, CA
65+ annotation. title = pinEntity . title
66+ annotation. subtitle = pinEntity . weather
5167 map. addAnnotation ( annotation)
5268
5369 return map
@@ -66,13 +82,9 @@ final class PinDetailViewController: UIViewController {
6682 return button
6783 } ( )
6884
69- @objc func dismissButtonTapped( ) {
70- self . dismiss ( animated: true , completion: nil )
71- }
72-
7385 // 리뷰 테이블뷰 설정
7486 private func setupReviewTable( ) {
75- pinTableView = UITableView ( frame: . zero, style: . grouped)
87+ // pinTableView = UITableView(frame: .zero, style: .grouped)
7688 pinTableView. estimatedRowHeight = UITableView . automaticDimension
7789 pinTableView. dataSource = self
7890 pinTableView. delegate = self
@@ -122,12 +134,43 @@ final class PinDetailViewController: UIViewController {
122134 $0. top. equalTo ( mapView. snp. bottom)
123135 $0. bottom. equalTo ( reviewPanelContainer. snp. top)
124136 }
137+ }
138+ }
139+
140+
141+
142+ // MARK: - objc function
143+ extension PinDetailViewController {
144+
145+ @objc func dismissButtonTapped( ) {
146+ self . dismiss ( animated: true , completion: nil )
147+ }
148+
149+ @objc func pinMenuButtonTapped( ) {
150+ let actionSheet = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
151+
152+ let editAction = UIAlertAction ( title: " 수정 " , style: . default) { _ in
153+ print ( " 수정 " )
154+ let vc = PinEditViewController ( )
155+ vc. modalPresentationStyle = . fullScreen
156+ self . present ( vc, animated: true , completion: nil )
157+ }
158+ let deleteAction = UIAlertAction ( title: " 삭제 " , style: . destructive) { _ in
159+ print ( " 삭제 " )
160+ }
161+ let cancelAction = UIAlertAction ( title: " 취소 " , style: . cancel, handler: nil )
125162
163+ actionSheet. addAction ( editAction)
164+ actionSheet. addAction ( deleteAction)
165+ actionSheet. addAction ( cancelAction)
126166
167+ present ( actionSheet, animated: true , completion: nil )
127168 }
128169
129170}
130171
172+
173+
131174// MARK: - Delegate
132175extension PinDetailViewController : UITableViewDataSource , UITableViewDelegate {
133176
@@ -170,28 +213,16 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate {
170213 // viewForHeaderInSection
171214 func tableView( _ tableView: UITableView , viewForHeaderInSection section: Int ) -> UIView ? {
172215 let header = PinDetailHeader ( )
216+ header. pinDate. text = pinEntity. date. koreanDateString ( )
217+ header. pinTitle. text = pinEntity. title
218+ header. pinImageView. image = pinEntity. mediaPath
219+ header. pinWeather. text = pinEntity. weather
220+ header. pinDescription. text = pinEntity. description
173221 header. pinMenuButton. addTarget ( self , action: #selector( pinMenuButtonTapped) , for: . touchUpInside)
174222 return header
175223 }
176224
177- @objc func pinMenuButtonTapped( ) {
178- let actionSheet = UIAlertController ( title: nil , message: nil , preferredStyle: . actionSheet)
179-
180- let editAction = UIAlertAction ( title: " 수정 " , style: . default) { _ in
181- print ( " 수정 " )
182- self . present ( PinEditViewController ( ) , animated: true , completion: nil )
183- }
184- let deleteAction = UIAlertAction ( title: " 삭제 " , style: . destructive) { _ in
185- print ( " 삭제 " )
186- }
187- let cancelAction = UIAlertAction ( title: " 취소 " , style: . cancel, handler: nil )
188-
189- actionSheet. addAction ( editAction)
190- actionSheet. addAction ( deleteAction)
191- actionSheet. addAction ( cancelAction)
192-
193- present ( actionSheet, animated: true , completion: nil )
194- }
225+
195226
196227 // estimatedHeightForHeaderInSection
197228 func tableView( _ tableView: UITableView , estimatedHeightForHeaderInSection section: Int ) -> CGFloat {
@@ -211,5 +242,5 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate {
211242
212243
213244#Preview {
214- PinDetailViewController ( )
245+ PinDetailViewController ( PinEntity . sampleData [ 0 ] )
215246}
0 commit comments