It's not possible for Swift to add cells in Table view



  • I have UITableView♪ I'm trying to remove the cells from the first and the only section, making their meaning dynamic. Here's my controller:

    import UIKit
    

    class SettingsController: UITableViewController {

    var sections = [10, 15, 30]
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sections.count
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("minutesIntervalCell", forIndexPath: indexPath)
    cell.textLabel?.text = String(sections[indexPath.row])
    return cell
    }
    

    }

    This is what I have in Main.stroyboard:

    введите сюда описание изображения

    When this is opening, this is a mistake:

    Terminating app due to uncaught exception 'NSRangeException', reason:
    '*** -[_NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]

    I understand the problem here is that there's only one cell in the Vuche itself, and I'm trying to ask three, but I'm in the code saying that the cells will be three, and he feels like he still thinks the cell is only one.

    I've got my hair on my mouth, what to do. Please help.



  • Looks like you're in the building. UITableViewController In Main.storyboard, the type of cells is static, not dynamic. Check this moment.

    In addition, there are two methods to create cells: tableView.dequeueReusableCellWithIdentifier("minutesIntervalCell", forIndexPath: indexPath) He'll try to set up a cell without checking out the cash. This method requires the cell and identifier to be registered as a preliminary challenge to the method tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "minutesIntervalCell")

    Second method tableView.dequeueReusableCellWithIdentifier("minutesIntervalCell") highly recommended for use, i.e. first, checking the presence of cells in the kash, which has a positive impact on productivity, and secondly, not limited to additional requirements and returning Optional




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2