본문 바로가기

iOS

(87)
[iOS] scrollview autolayout 5/12 이해가 안돼서 다시 수정합니다 ㅎ 스크롤 뷰를 만들기 위해서 스크롤이 가능한 content 영역을 제공해야합니다. 크게 보면 스크롤 뷰위에 뷰를 올려서 그 뷰의 크기만큼 스크롤이 가능하게 해야합니다. 그리고 여러가지 조정을 해주면 되는데.. 우선 scroll view를 가져오고 크기를 화면에 꽉차게 맞춰줍니다. 그리고 스크롤뷰의 constraint를 모두 0으로 맞춰줍니다. ( 스크롤뷰를 선택하고 bottom은 safe area가 아닌 superview에 맞춰줍니다. + 추가 Sperview도 있고 Content Layout Guide 도 있습니다. 추후에 무슨 차이인지 다시 공부.. ) 그다음 UIView (컬렉션 뷰, 이미지 뷰 모두 가능합니다.) 를 추가해주고, 첫번째 방법 마찬가지로 화면..
[iOS] The data couldn’t be read because it is missing. 테이블 셀에 json 데이터를 가져오던 도중에 발생한 오류 do { self.countries = try jsonDecoder.decode([Country].self, from: dataAsset.data) } catch { print("에러나따2") print(error.localizedDescription) } 콘솔창에 The data couldn’t be read because it is missing. 가 떠버렸다. json 데이터를 받아올 구조체를 선언한 파일로 가서 struct Country: Codable { let countryName: String let assetName: String enum CodingKeys: String, CodingKey { case countryName = "..
[iOS] segue로 데이터 전달 ViewController.swift override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let nextViewController: SecondViewController = segue.destination as? SecondViewController else { return } guard let cell: UITableViewCell = sender as? UITableViewCell else { return } nextViewController.textToSet = cell.textLabel?.text } ViewController에서 SecondViewController로 데이터를 넘겨줄 때 사용한다. guard let으..
[iOS] UITableView Tabel: Table view, data source, delegate 인터페이스 빌더 Table view 넣기 Table cell 넣기 @IBOutlet UITableView 연결하기 스토리보드에서 dataSource, delegate를 View Controller 에 연결하기 코드 (4번) self.tableView.delegate = self self.tableView.dataSource = self 필수구현 numberOfRowsInSecion: 각 row의 행이 몇개인지 cellForRowAt: 각 cell에 들어갈 내용 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch sect..
[iOS] Singleton Singleton 패턴을 사용하던 도중에 shared 로 선언할 뿐만 아니라 한가지를 더 추가해야한다는 사실을 알았다. 하나의 인스턴스로만 사용하기 때문에 외부에서 새로운 객체를 생성할 수 없도록 해야한다. 외부에서 생성할 수 없게 해야하기 때문에 initialize 함수를 private 으로 선언해야 외부에서 생성이 불가능하다. 고로 인스턴스 생성 + private init 함수 생성 을 해야 singleton 패턴을 사용할 수 있다. 예시 class UserInformation { static let shared: UserInformation = UserInformation() var id: String? var password: String? var checkPassword: String? var ..
[iOS] UITextField 암호화 시 Strong Password 회원가입 창을 만들때 암호를 가리기 위해서 passwordTextField.isSecureTextEntry = true 코드를 넣었는데, Strong Password 가 뜨면서 가려지지도 않고, 입력한게 보이지도 않았다. (가로로도 눕혀봤는데 안보이더라ㅜ) passwordTextField.textContentType = .password passwordTextField.isSecureTextEntry = true textContentType 이 그냥 password일때는 Strong Password가 뜨고, newPassword로 해야 암호가 가려지게 적혀진다. [AutoFill] Cannot show Automatic Strong Passwords for app bundleID: com.neuli.my..
[iOS] UIDatePicker, UIGestureRecognizer UIDatePicker stotyboard 에 DatePicker 와 Label 올려두기 DateFormatter 를 사용하여 날짜를 Label 에 나타내기 let dateFormatter: DateFormatter = { let formatter: DateFormatter = DateFormatter() formatter.dateFormat = "yyyy/MM/dd hh:mm:ss" // formatter.dateStyle = .medium // formatter.timeStyle = .medium return formatter }() 1. format 을 직접 지정하려면 .dateFormat 을 변경해준다. ex) "yyyy/MM/dd" 2. 기본 스타일: .dateStyle, .timeStyle 애..
[iOS] Delegate Delegation Design Pattern 하나의 객체가 다른 객체를 대신해 동작 또는 조정할 수 있는 기능을 제공합니다. Delegation design pattern 은 Foundation, UIKit, AppKit 그리고 Cocoa Touch 등 애플의 프레임워크에서 광범위하게 활용하고 있습니다. 주로 프레임워크 객체가 위임을 요청하며, 커스텀 컨트롤러 객체가 위임을 받아 특정 이벤트에 대한 기능을 구현합니다. Delegation design pattern 은 커스텀 컨트롤러에서 세부 동작을 구현함으로써 동일한 동작에 대해 다양한 대응을 할 수 있게 해 줍니다. UITextFieldDelegate (예) // 대리자에게 특정 텍스트 필드의 문구를 편집해도 되는지 묻는 메서드 func textFi..