@@ -27,6 +27,7 @@ public class MyOwnedWineInfoViewController: UIViewController, ChildViewControlle
2727
2828 public override func viewWillAppear( _ animated: Bool ) {
2929 super. viewWillAppear ( animated)
30+ fetchMyWineAPI ( )
3031 self . view. addSubview ( indicator)
3132 self . hidesBottomBarWhenPushed = true
3233 self . navigationController? . setNavigationBarHidden ( false , animated: animated)
@@ -41,32 +42,30 @@ public class MyOwnedWineInfoViewController: UIViewController, ChildViewControlle
4142 super. viewDidLoad ( )
4243 setupUI ( )
4344 setupNavigationBar ( )
44- setWineData ( )
45+ setActions ( )
4546 wineDetailView. setEditButton ( showEditButton: true )
4647 }
4748
4849 public override func viewDidAppear( _ animated: Bool ) {
4950 super. viewDidAppear ( animated)
5051 logScreenView ( fileName: #file)
51- fetchMyWineAPI ( )
5252 }
5353
54+ private func setActions( ) {
55+ wineDetailView. editButton. addTarget ( self , action: #selector( editButtonTapped) , for: . touchUpInside)
56+ deleteButton. addTarget ( self , action: #selector( deleteButtonTapped) , for: . touchUpInside)
57+ }
58+
59+ @MainActor
5460 private func setWineData( ) {
5561 guard let currentWine = self . registerWine else { return }
56- var displayName = currentWine. wineName
57- if let vintage = currentWine. vintage {
58- displayName += " \( vintage) "
59- }
60-
61- header. setWineName ( displayName)
62+ header. setWineName ( currentWine. getDisplayedName ( ) )
6263 header. infoView. image. sd_setImage ( with: URL ( string: currentWine. wineImageUrl) , placeholderImage: UIImage ( named: " placeholder " ) )
6364 header. infoView. typeContents. text = " \( currentWine. wineCountry) , \( currentWine. wineRegion) "
6465 header. infoView. countryContents. text = currentWine. wineVariety
6566 header. infoView. kindContents. text = currentWine. wineSort
6667
6768 self . setWineDetailInfo ( currentWine)
68- wineDetailView. editButton. addTarget ( self , action: #selector( editButtonTapped) , for: . touchUpInside)
69- deleteButton. addTarget ( self , action: #selector( deleteButtonTapped) , for: . touchUpInside)
7069 }
7170
7271 // MARK: - Setup Methods
@@ -177,28 +176,34 @@ public class MyOwnedWineInfoViewController: UIViewController, ChildViewControlle
177176 Task {
178177 do {
179178 let data = try await networkService. fetchMyWine ( myWineId: registerWine!. myWineId)
180- DispatchQueue . main. async { [ self ] in
181- self . registerWine = MyWineViewModel (
182- myWineId: data. myWineId,
183- wineId: data. wineId,
184- wineName: data. wineName,
185- vintage: data. vintageYear,
186- wineSort: data. wineSort,
187- wineCountry: data. wineCountry,
188- wineRegion: data. wineRegion,
189- wineVariety: data. wineVariety,
190- wineImageUrl: data. wineImageUrl,
191- purchaseDate: data. purchaseDate,
192- purchasePrice: data. purchasePrice,
193- period: data. period
194- )
179+
180+ registerWine = MyWineViewModel (
181+ myWineId: data. myWineId,
182+ wineId: data. wineId,
183+ wineName: data. wineName,
184+ vintage: data. vintageYear,
185+ wineSort: data. wineSort,
186+ wineCountry: data. wineCountry,
187+ wineRegion: data. wineRegion,
188+ wineVariety: data. wineVariety,
189+ wineImageUrl: data. wineImageUrl,
190+ purchaseDate: data. purchaseDate,
191+ purchasePrice: data. purchasePrice,
192+ period: data. period
193+ )
194+
195+ DispatchQueue . main. async { [ weak self] in
196+ guard let self = self else { return }
195197 self . setWineData ( )
196- // self.needUpdate = false
198+
197199 self . view. hideBlockingView ( )
198200 }
199201 } catch {
200- self . view. hideBlockingView ( )
201- errorHandler. handleNetworkError ( error, in: self )
202+ DispatchQueue . main. async { [ weak self] in
203+ guard let self = self else { return }
204+ self . view. hideBlockingView ( )
205+ errorHandler. handleNetworkError ( error, in: self )
206+ }
202207 }
203208 }
204209 }
0 commit comments