私は、セクションごとに静的な5セクションと2行、しかし1行の最後のセクションを持つUITableViewControllerを持っています。スウィフトUITableViewController numberOfSections境界1を超えるインデックス[0 .. 0]
私はストーリーボードにテーブルを作成し、ストーリーボードを介してセクションとローの数を設定しました。私はまた、行やセクションの正しい数設定したプロトコル機能で:
override func numberOfSections(in tableView: UITableView) -> Int {
return 5
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 4) {
return 1
} else {
return 2
}
}
をしかし、私はこのエラーを取得する:
'NSRangeException', reason: '*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
私がもしあるため、このエラーはnumberOfSections
機能に関連していると考えています私は5から0に変更し、うまく動作します。私はストーリーボードで定義すると、セクションの配列がゼロになることを理解していません。私は見ていない簡単な解決法はありますか?
私もアップリンクデリゲート源を持っている、と私のデータソースは、テーブル全体がストーリーボードで作成されたように、アレイの任意の種類ではなく、ラベルが含まれている、など
EDIT
全体のビューコントローラのためのコード:
import UIKit
class RideSummaryTableViewController: UITableViewController {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var ratingLabel: UILabel!
@IBOutlet var originStreetLabel: UILabel!
@IBOutlet var originCityLabel: UILabel!
@IBOutlet var destStreetLabel: UILabel!
@IBOutlet var destCityLabel: UILabel!
@IBOutlet var rateLabel: UILabel!
@IBOutlet var paymentButton: UIButton!
var paymentText = "Request Payment"
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.paymentButton.setTitle(paymentText, for: .normal)
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 5
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 4) {
return 1
} else {
return 2
}
}
/*
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
*/
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
確かに、ストーリーボードで静的セルを選択しましたか?万が一、ダイナミックセルに値を設定していない。私はダイナミックなセルを持つセクションを作成することは可能だとは思わないが。コントローラー全体を投稿できますか? – Devster101
はい私はストーリーボードでスタティックセルを選択しました。 View Controller全体のクラスを投稿するようになりました。 –