본문 바로가기

전체 글13

cell의 이벤트 에러 [Swift] 이 글은 뇌피셜을 기반으로 합니다. cell에게 이벤트 주는 요소를 두 가지정도로 나누면 UIControl의 서브클래스, UIControl을 상속하지 않는 UIView 로 나눌 수 있을 것 같습니다. 나누는 기준에 대해 말씀드리면 UIControl의 서브클래스들은 cell에 넣었을 때 클릭이 잘 되는 설정이 따로 되어있는건지는 모르겠지만, cell 자체에 넣어도 지금 말하려는 문제가 생기지 않습니다. 문제는 후자인데, cell에 contentView 라는 서브뷰가 있습니다. 그리고 이 서브뷰는 isUserInteractionEnabled가 true로 설정되어있어요. 또한 후자의 뷰에게 이벤트를 주려면 let iv = UIView() let tap = UITapGestureRecognizer(target:.. 2023. 8. 21.
addGestureRecognizer와 addTarget 차이 [Swift] 버튼이나, view에게 클릭했을 때 이벤트를 발생하도록 하는 방법이 두 가지정도 되는것같다. UIView를 생성해서 UITapGestureRecognizer를 이용하거나, let iv = UIView() let tap = UITapGestureRecognizer(target: self, action: #selector(handleProfileImageView)) iv.isUserInteractionEnabled = true iv.addGestureRecognizer(tap) addTarget 함수를 이용하는 방법이다. let button = UIButton() button.addTarget(self, action: #selector(tapFollowButton), for: .touchUpInside) 첫.. 2023. 8. 21.
프로퍼티 감시자가 호출되는 경우 [Swift] struct Notification { let postImageURL: String? let postID: String? var userIsFollowed = false } Notification 구조체가 있다고 합시다. var notifications = [Notification]() { didSet { tableView.reloadData() } } 이 구조체를 이용해서 프로퍼티 감시자를 가진 배열을 하나 만들었습니다. 프로퍼티 감시자는 다음 세가지 모든 상황에서 호출됩니다. self.notifications = notifications notifications[index] = Notification()​ notifications[index].userIsFollowd = isFollowed 1. 프로.. 2023. 8. 20.
UITextView의 intrinsicContentSize UITextView의 isScrollEnabled 가 false일 때 intrinsicContentSize가 활성화 됩니다. 자세히 봅시다. - textView를 생성해서 isScrollEnabled를 true 로 주면 (-1.0, -1.0) 이 출력됩니다. swift에서는 intrinsicContentSize 가 없을 때 (-1, -1)의 값을 가집니다. (항상 -1, -1을 가지는지는 모르겠으나 UIView에서도 값이 없을 때도 -1, -1을 가집니다.) - 이번엔 isScrollEnabled 가 false 로 주고 출력해보면 (10.0, 52.0) 이 출력됩니다. intrinsicContentSize 가 생겼습니다. 다시 정리를 하면, isScrollEnabled를 false로 설정하면 UIText.. 2023. 8. 18.