커스텀 셀 등록

테이블 뷰에서 커스텀 셀을 재사용 큐(Reusable Queue)에서 관리하려면 먼저 테이블 뷰에 해당 커스텀 셀을 등록해주어야 한다.

tableView.**register(CustomCell.self, forCellReuseIdentifier: "CustomCell")**

Carmu 앱에서 사용 예시

셀 구성

let cell = tableView.dequeueReusableCell(
		withIdentifier: "CustomCell",
		for: indexPath
) as! CustomCell

Carmu 앱에서 사용 예시

// 셀 구성
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    **guard let cell = tableView.dequeueReusableCell(
        withIdentifier: FriendListTableViewCell.cellIdentifier,
        for: indexPath
    ) as? FriendListTableViewCell else {
        return UITableViewCell()
    }**
    if let friend = friendList[indexPath.section][1] as? User {
        cell.nicknameLabel.text = friend.nickname
        // 친구 이미지 불러오기
        if let imageURL = friend.imageURL {
            loadProfileImage(urlString: imageURL) { friendImage in
                if let friendImage = friendImage {
                    cell.profileImageView.image = friendImage
                } else {
                    cell.profileImageView.image = UIImage(named: "profile")
                }
            }
        }
    }
    let chevronImage = UIImageView(image: UIImage(systemName: "chevron.right"))
    chevronImage.tintColor = UIColor.semantic.textBody
    cell.accessoryView = chevronImage
    return cell
}