title: How to build a Table View with specific number of rows?
body: <p>I have been reading similar questions and until now neither has solved this error or I have not found it.</p>
  
  <p>I have a TableView and I need the table to have a specific number of rows.</p>
  
  <p>Now it works with a count of notifications from a array. In this array, I keep the notifications that come from the server.
  But I want that if this array count is greater than 40, the rows are 40 and they not are the count of the array.</p>
  
  <p>This is my code:</p>
  
  <pre><code>class ClassName: UITableViewController, UITabBarControllerDelegate {
      public var notifications: [APINotification] = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.tabBarController?.delegate = self
          tableView.rowHeight = UITableViewAutomaticDimension
          tableView.estimatedRowHeight = 140
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      override func viewDidAppear(_ animated: Bool) {
          self.notifications = []
          self.getLastNotifications()
          APIAuth.shared.count_badge = 0
          self.tabBarController?.tabBar.items![0].badgeValue = nil
      }
  
      public func getLastNotifications() {
          let req = Notification()
          req.getLastNotifications(onComplete: {events in
              self.notifications = events
  
              DispatchQueue.main.async(execute: {
                  self.tableView.reloadData()
              })
          })
      }
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return self.notifications.count
      } 
  
      // There is just one row in every section
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return 1
      }
  
      // Set the spacing between sections
      override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
          return 10
      }
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let event = self.notifications[indexPath.section]
          let cell = tableView.dequeueReusableCell(withIdentifier: "controller", for: indexPath) as! Controller
  
          cell.bodyLbl.text = event.description
          cell.typelbl.text = event.type
          cell.typelbl.sizeToFit()
          cell.titleLbl.text = event.title
          cell.subjectLbl.text = event.subject?.name
  
          return cell
      } }
  </code></pre>
  
  <p>Thanks for your help!</p>