사용자 정의 tableViewCell이있는 섹션이 있는데이 셀에는 두 개의 텍스트 필드가 있습니다. 이 셀은 한 텍스트 필드에 사용자 - 국가 코드의 전화 번호를 표시하고 다른 텍스트 필드에는 번호를 표시하는 데 사용됩니다.UITextFields를 사용하여 tableViewCell을 다시 사용하면 배열에서 동일한 데이터가 반환됩니다.
서비스에서 데이터를 가져오고 사용자가 전화기 개수가 여러 개인 경우 numberOfRowsInSection 및 cellForRowAtIndexPath를 업데이트합니다. 여기까지는 아무런 문제가 없습니다.
예를 들어 사용자가 전화가 두 개인 경우 numberOfRowsInSection에서 2를 반환하고 두 개의 셀 (두 개의 textField가있는 동일한 맞춤 셀)을 표시합니다.
문제점 : 두 데이터 모두 두 번째 전화 번호와 동일한 데이터를 얻습니다. 하지만 맞춤식 셀 텍스트 필드에 차례로 표시되는 전화 번호 목록이 필요합니다. 여기
내 코드입니다 :
numberOfRowsInSection
public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 3:
return (user.phones?.count)!
default:
return 1
}
}
cellForRowAtIndexPath
public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
case .ContactPhones:
if contactCellExpanded == true {
cell = tableView.dequeueReusableCellWithIdentifier("PhoneCell") as? PhoneCell
}
case .ContactEmail:
if contactCellExpanded == true {
cell = tableView.dequeueReusableCellWithIdentifier("EmailCell") as? EmailCell
}
default:
break
}
PhoneCell
import UIKit
class PhoneCell: ProfileCell {
@IBOutlet weak var countryCode: UITextField!
@IBOutlet weak var addPhoneButton: UIButton!
@IBOutlet weak var teleNumber: UITextField!
@IBAction func addPhoneButtonAction(sender: AnyObject) {
}
override func configure(withUser user: XtraUser, language: String, indexPath: NSIndexPath) {
super.configure(withUser: user, language: language, indexPath: indexPath)
self.countryCode.borderStyle = .RoundedRect
self.teleNumber.borderStyle = .RoundedRect
if let userPhoneInfo = user.phones {
for i in 0..<userPhoneInfo.count {
print ("numbers \(userPhoneInfo[i].number)")
self.countryCode.text = userPhoneInfo[i].country
self.teleNumber.text = userPhoneInfo[i].number
}
}
}
}
사용 가능한 경우 for 루프를 사용하여 숫자 목록을 가져 오는 것으로 알고 있지만 각 값을 셀의 textField에 어떻게 할당합니까?
제발 도와주세요! 이후 사전
간단합니다. 내 멍청한 두뇌에 맞지 않았어 !!! : '( –
원래 질문에 대한 연장 질문이 있습니다. 제발 도와 주실 수 있습니까? 사용자가 전화기를 추가 할 수도 있습니다 - 추가 버튼이 있고 "user.phones? .count"의 수가 증가합니다. on 추가, 그것은 textFields의 값을 지운다. 이유를 알아낼 수 없다! –
잘 구성 방법에 중단 점을 넣고 추가 단추를 클릭 한 후 무슨 일이 일어나는 지 확인하십시오. 어쩌면 빈 문자열로 텍스트 필드를 채울 것인가? –