보통 코드로 셀을 등록할 때는 꼭 register을 이용해서 등록을 해줘야 됨.
단, 스토리보드에 넣었을 경우에는 이 경우 생략
//viewDidLoad
tableView.register(...
- xib
mainTableView.register(UINib(nibName: "yearCalendarCellTableViewCell", bundle: nil), forCellReuseIdentifier: yearCalendarCellTableViewCell.identifier)
- code
mainTableView.register(yearCalendarCellTableViewCell.self, forCellReuseIdentifier: yearCalendarCellTableViewCell.identifier)
속성 감시자로 셀 표현 하는 방법
class MemberTableViewCell: UITableViewCell {
var member: Member? {
didSet {
print("멤버 변경")
self.mainImageView.image = member?.memberImage
self.addressLabel.text = member?.address
self.memberNameLabel.text = member?.name
}
}
...
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MemberTableViewCell", for: indexPath) as? MemberTableViewCell else { return UITableViewCell() }
**cell.member = memberListManager[indexPath.row]**
//기존
// cell.mainImageView.image = memberListManager[indexPath.row].memberImage
// cell.memberNameLabel.text = memberListManager.getMemberList()[indexPath.row].name
// cell.addressLabel.text = memberListManager.getMemberList()[indexPath.row].address
return cell
}
Delete 버튼 숨기기(move만 하려면)
//delete 버튼 숨기기
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .none
}
맨 마지막 셀의 separator 지우기
public extension UITableView {
func isLast(for indexPath: IndexPath) -> Bool {
let indexOfLastSection = numberOfSections > 0 ? numberOfSections - 1 : 0
let indexOfLastRowInLastSection = numberOfRows(inSection: indexOfLastSection) - 1
return indexPath.section == indexOfLastSection && indexPath.row == indexOfLastRowInLastSection
}
}
-------------------------------------------------
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = v.tableView.dequeueReusableCell(withIdentifier: RecentSearchKeywordTableViewCell.identifier, for: indexPath) as? RecentSearchKeywordTableViewCell else { return UITableViewCell() }
if tableView.isLast(for: indexPath) {
DispatchQueue.main.async {
cell.separatorInset = UIEdgeInsets(top: 0, left: cell.bounds.size.width, bottom: 0, right: 0)
}
}
return cell
}