본문 바로가기
iOS/iOS

CustomView의 super

by 패쓰킴 2023. 1. 4.
728x90

customView가 사용되는 곳에 따라 형태나 동작을 다르게 하고 싶을 때가 있다.

그래서 현재 customView의 위치를 가져오기 위해 방법을 찾아보면 

- (UIViewController *) firstAvailableUIViewController {
  UIResponder *responder = [self nextResponder];
  while (responder != nil) {
    if ([responder isKindOfClass:[UIViewController class]]) {
      return (UIViewController *)responder;
    }
    responder = [responder nextResponder];
  }
  return nil;
 }

위 와 같은 직접 view가 controller를 가져오는 방식의 코드를 볼 수 있다.

하지만 

- Your view should not need to access the view controller directly.
- The view should instead be independent of the view controller, and be able to work in different contexts.
- Should you need the view to interface in a way with the view controller, the recommended way, and what Apple does across Cocoa is to use the delegate pattern.

정확히 이해는 못했지만 뷰에서 컨트롤러로 직접 접근 하는것 보다 딜리게이트 패턴을 사용하라는 뜻으로 이해된다.

출처 및 참고: https://stackoverflow.com/questions/1340434/get-to-uiviewcontroller-from-uiview

728x90

'iOS > iOS' 카테고리의 다른 글

빌드한 앱의 권한 제어  (0) 2023.01.11
설정앱의 특정 화면으로 이동??  (0) 2023.01.06
Core Data  (0) 2023.01.04
UIViewController PopUp  (0) 2022.12.21
UITableView  (0) 2022.12.19

댓글