Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[πŸ“UIKit μ½”λ“œμ»¨λ²€μ…˜πŸ“] #17

Open
shippingpark opened this issue Nov 10, 2024 · 0 comments
Open

[πŸ“UIKit μ½”λ“œμ»¨λ²€μ…˜πŸ“] #17

shippingpark opened this issue Nov 10, 2024 · 0 comments
Labels
Rule 악동쿠킀듀이 μ§€μΌœμ•Ό ν•  우리λ₯Ό μœ„ν•œ λ£°μž…λ‹ˆλ‹€

Comments

@shippingpark
Copy link
Collaborator

shippingpark commented Nov 10, 2024

속성, λ©”μ„œλ“œ μž‘μ„± μˆœμ„œ

μˆœμ„œ

class CustomView: UIView {
// (μƒμœ„μ£Όμž… 값이 ν•„μš”ν•˜λ‹€λ©΄ μ—¬κΈ°)
// MARK: - Views
// MARK: - Output  // ⭐️
// MARK: - Properties
// MARK: - Initializers
// MARK: - LifeCycle
// MARK: - Setup Methods
  // func setupView()
  // func setupConstraints()
// MARK: - Input // ⭐️
// MARK: - Private Methods 
}

// MARK: - DataSource  
extension CustomView: DataSource {
}
// MARK: - Delegate 
extension CustomView: Delegate {
}

MARK: - Setup Methods λͺ…λͺ… κ·œμΉ™

  func setupView() // λ·°λ₯Ό μ˜¬λ¦¬λŠ” μž‘μ—… μ‹œ 
  func setupConstraints() // λ ˆμ΄μ•„μ›ƒ μž‘μ—… μ‹œ 

UIView μ—μ„œμ˜ Input Output λͺ…λͺ… κ·œμΉ™

Input μ΄λž€?

View μž…μž₯μ—μ„œ μ™ΈλΆ€λ‘œ λΆ€ν„° 받아와야 ν•˜λŠ” 값을 νŒŒλΌλ―Έν„°λ‘œ 전달받기 μœ„ν•΄ μ‘΄μž¬ν•˜λŠ” λ©”μ„œλ“œ

Output μ΄λž€?

λ‚˜λ₯Ό μƒμ„±ν•œ μ£Όμ²΄μ—κ²Œ ν΄λ‘œμ € ν˜•νƒœλ‘œ 전달 λ°›μ•„ Event μ‹œμ μ— μ‹€ν–‰μ‹œμΌœ μ£Όκ³  싢은 ν΄λ‘œμ €

Input Ouput λͺ…λͺ… κ·œμΉ™

Input

// MARK: - Setup Methods λ©”μ„œλ“œ μ•„λž˜
// MARK: - Input
마크λ₯Ό μž‘μ„±ν•˜κ³  κ·Έ ν•˜μœ„μ— public으둜 μž‘μ„±

  • λ©”μ„œλ“œ λͺ…이 configure 둜 λλ‚˜λ„λ‘ μž‘μ„±
    [μ˜ˆμ‹œ]
public func setConfigure(info: TravelCellInfo) {
   let (mainTitle, dateTitle) = info
   titleLabel.text = mainTitle
   dateLabel.text = dateTitle
 }

Output

// MARK: - Properties 속성듀 μ•„λž˜
// MARK: - Output
마크λ₯Ό μž‘μ„±ν•˜κ³  κ·Έ ν•˜μœ„μ— public으둜 μž‘μ„±

  • ν΄λ‘œμ € λͺ…이 on으둜 μ‹œμž‘ν•˜λ„λ‘ μž‘μ„±
  public var onSelectedCell: (IndexPath -> Void)?

μ˜ˆμ‹œ - UITavleViewλ₯Ό μƒμ†ν•œ TravelTableView

class TravelTableView: UITableView {

  // MARK: - Output 
  public var onSelectedCell: (IndexPath -> Void)?

  // MARK: - Properties
  private var travelInfos: [TravelCellInfo] = [] {
    didSet { reloadData() }
  }
  
  // MARK: - Initializers
  override init(frame: CGRect, style: UITableView.Style) {
    super.init(frame: frame, style: style)
    setupView()
    setupConstraints()
  }
  
  required init?(coder: NSCoder) {
    super.init(coder: coder)
    setupView()
    setupConstraints()
  }
  
  // MARK: - Setup Methods
  private func setupView() {
    let travelCell = UINib(nibName: TravelTableViewCell.identifier, bundle: nil)
    register(travelCell, forCellReuseIdentifier: TravelTableViewCell.identifier)
    self.backgroundColor = .clear
    self.dataSource = self
    self.delegate = self
  }
  
  private func setupConstraints() {}

// MARK: - Input  
  public func setConfigure(info travelInfos: [TravelCellInfo]) {
    self.travelInfos = travelInfos
  }
}

// MARK: - DataSource  
extension TravelTableView: UITableViewDataSource {
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return travelInfos.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: TravelTableViewCell.identifier, for: indexPath) as? TravelTableViewCell else {
      return UITableViewCell()
    }
    
    let travelInfo = travelInfos[indexPath.row]
    cell.setConfigure(info: travelInfo)
    
    return cell
  }
}

// MARK: - Delegate
extension TravelTableView: UITableViewDelegate {
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    onSelectedCell?(indexPath)
  }
}
@shippingpark shippingpark added the Rule 악동쿠킀듀이 μ§€μΌœμ•Ό ν•  우리λ₯Ό μœ„ν•œ λ£°μž…λ‹ˆλ‹€ label Nov 10, 2024
@shippingpark shippingpark changed the title UIView / UIViewController 상속 μ‹œ Code Convention [UIView / UIViewController 상속 μ‹œ Code Convention] Nov 10, 2024
@shippingpark shippingpark changed the title [UIView / UIViewController 상속 μ‹œ Code Convention] [🧸UIKit Code Convention🧸] Nov 10, 2024
@shippingpark shippingpark changed the title [🧸UIKit Code Convention🧸] [🧸UIKit μ½”λ“œμ»¨λ²€μ…˜πŸ§Έ] Nov 10, 2024
@shippingpark shippingpark changed the title [🧸UIKit μ½”λ“œμ»¨λ²€μ…˜πŸ§Έ] [πŸ“UIKit μ½”λ“œμ»¨λ²€μ…˜πŸ“] Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rule 악동쿠킀듀이 μ§€μΌœμ•Ό ν•  우리λ₯Ό μœ„ν•œ λ£°μž…λ‹ˆλ‹€
Projects
None yet
Development

No branches or pull requests

1 participant