순진이의 하루/study정리
3. 스토리보드 삭제, tableView cell configuration_2022.08.08
순진이
2022. 8. 4. 14:58
스토리보드 삭제하는 방법2 (SceneDelegate 삭제)
1. info.plist에서 삭제
2. Main과 SceneDelegate 파일 삭제
3. AppDelegate에서 작업
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.backgroundColor = .systemBackground
window?.makeKeyAndVisible()
return true
}
}
<sceneDelegate를 지우는 이유>
- iOS13부터 split View를 지원하게 되면서 각 화면을 window로 나누게 됨
- 그 이전에는 AppDelegate만 있었지만 그 이후에는 SceneDelegate로 나눠진다.
cell의 기본 속성 설정
tableView cell에 관한 속성들 중 textLabel과 detailTextLabel 등이 곧 deprecated될 예정.
이 대신 defaultContentConfiguration가 있음
let cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
var content = cell.defaultContentConfiguration()
content.text = "Game"
content.secondaryText = "Detail"
content.secondaryTextProperties.color = .black
content.secondaryTextProperties.font = UIFont.systemFont(ofSize: 14)
cell.contentConfiguration = content
cell.accessoryType = .disclosureIndicator
cell.selectionStyle = .none // 선택됐을 때 selection 처리 안되도록(=회색 음영 처리)
return cell
완성된 모습 ⬇️
https://developer.apple.com/documentation/uikit/uitableviewcell/3601058-defaultcontentconfiguration
Apple Developer Documentation
developer.apple.com
UITableView의 생성자 중 아래 생성자 사용
style은 UITableViewCell.CellStyle라는 enum 타입인데, 아래와 같은 case가 있음.
원하는 모양을 사용하면 됨