私はuitableviewcontrollerを構築しようとしており、swiftを扱うのが難しいです。numberOfRowsInSectionが呼び出されるたびに、それは4回呼び出されてからアプリケーションがクラッシュします。誰もこれを実装する方法を知っていますか?numberOfRowsInSectionがスウィフトでクラッシュする3
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6;
}
テーブルには6つのアイテムがあります。確認するために配列数を表示しました。これはフルビューコントローラです。
class PCRInpatientsViewController: UITableViewController
{
var listInpatient = [PCRPatient]();
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.none;
self.title = "Inpatients";
let view = self.view.frame;
let background = UIView(frame: view);
background.backgroundColor = Constants.medisasDarkGrey;
self.tableView.backgroundView = background;
self.definesPresentationContext = true;
getPatients();
createUI();
}
func getPatients() {
var array = [PCRPatient]();
let i = Patients.sharedInstance.patients
for int in 0..<i.count {
let d = i[int];
if d.status == PCRPatientStatus.PreAdmit {
print(d.name)
array.append(d);
}
}
print(array.count);
self.listInpatient = array;
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated);
}
func createUI(){
self.navigationController?.navigationBar.barTintColor = Constants.medisasRed;
self.navigationController?.navigationBar.isTranslucent = false;
self.navigationController?.navigationBar.tintColor = UIColor.white();
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white()];
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6;
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 150;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> PCRCustomCell {
let patient = listInpatient[indexPath.row];
print("sjddsodkso \(patient.name)");
let cell = PCRCustomCell(reuse: "Inpatient", patient: patient);
cell.contentView.backgroundColor = Constants.medisasGrey;
return cell;
}
}
私はチェックし、配列内に6つの項目があります。私はrtheフルビューコントローラを追加しました – PCR
それは元々何だったのですが、クラッシュしていたので6に変更しました。私が6と書いたらクラッシュするかどうか確認したいと思っていました。これは古いスウィフトでうまくいっていたでしょう。それがスウィフト3からのいくつかの変更が原因だと思います。 – PCR
私はもっと知識のある人に延期すると思います。私は問題が何かを見ることを楽しみにしています。 –