Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- API
- xib
- uisearchbar
- uikit
- Autolayout
- reduce()
- tableView
- 프로그래머스
- 알고리즘
- prefix()
- zip()
- Segue
- IOS
- swift
- 코드업 파이썬 기초 100제
- alamofire
- replacesubrange()
- suffix()
- String()
- GIT
- 싱글톤
- 코딩테스트
- Info.plist
- 클론코딩
- 라이징캠프
- 대문자소문자
- github
- joined()
- components()
- MVC
Archives
- Today
- Total
Daeng iOS
[iOS/UIKit] xib 파일로 테이블뷰 연결 후 터치이벤트&화면전환 본문
테이블뷰 셀을 xib로 연결했을 때 터치이벤트 구현하는 방법을 정리하려고 합니다~!
먼저 화면전환을 segue로 연결하고 Attributes inspector 에서 Identifier 을 지정해준다
[테이블뷰가 있는 컨트롤러]
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//터치이벤트
performSegue(withIdentifier: "detail", sender: indexPath.row)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "detail"{
let destination = segue.destination as? detailViewController
if let selectedIndex = sender as? Int{
destination?.name = menu.settingList[selectedIndex].name
destination?.sum = menu.settingList[selectedIndex].sum
destination?.Img = menu.settingList[selectedIndex].img
}
}
}
performSegue 메소드
현재 뷰컨트롤러의 스토리보드 파일에서 지정한 identifier 을 이용해 segue를 시작한다.
prepare 메소드
segue가 수행될 예정임을 뷰 컨트롤러에 알린다.
[detailViewController]
위에 코드에서 연결했던 swift 파일이다
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
func updateUI(){
detailName.text = name
detailSum.text = sum
detailImg.image = Img
}
위에서 받은 데이터를 받을 컨트롤러에서 연결한 아울렛 변수들에 넣어준다!!
'IOS > UIKit' 카테고리의 다른 글
[iOS/UIKit] 테이블 뷰 셀에서 속성이 유지되지 않는 버그 해결 2 - Delegate 사용 (0) | 2023.11.28 |
---|---|
[iOS/UIKit] 테이블 뷰 셀에서 속성이 유지되지 않는 버그 해결 1 - prepareForReuse() 사용 (0) | 2023.11.28 |
[iOS/UIKit](RC_Week3) UITableView를 이용한 프론트 구성하기 (0) | 2022.12.02 |
[iOS/UIKit](RC_Week2) 생명주기를 활용한 레이아웃 클론 프로그래밍 (0) | 2022.12.01 |
[iOS/UIKit](RC_Week1) 오토레이아웃 적용하여 어플 프론트 구성하기 (0) | 2022.11.30 |