title: add an item to UITableView on button click in iOS Swift
body: <p>I am new to iOS development and I am working with <a href="http://www.raywenderlich.com/77974/making-a-gesture-driven-to-do-list-app-like-clear-in-swift-part-1" rel="nofollow">this</a> tutorial , to create a simple TO-DO list app</p>
  
  <p>I have a view controller to which I have added a UITableView &amp; a UIBarButtonItem. I want to add an item (a title) to the UITableView on the UIBarButtonItem click. I had written the code but I am not sure whats wrong</p>
  
  <pre><code>class contactsMenu: UIViewController, UITableViewDataSource , UITableViewDelegate {
  
      @IBOutlet weak var tableView: UITableView!
  
      var toDoItems = [todoItem]()
      override func viewDidLoad() {
          super.viewDidLoad()
          tableView.dataSource = self
          tableView.delegate = self
          tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
          if toDoItems.count &gt; 0 {
              return
          }
      }
  
      override func viewDidAppear(animated: Bool) {
          tableView.reloadData()
      }
  
  
  
      @IBAction func addAGroupBtnclicked(sender: UIBarButtonItem) {
         toDoItems.append(todoItem(text: "ok"))
      }
  
      @IBAction func backBtn(sender: UIBarButtonItem) {
          self.dismissViewControllerAnimated(true, completion: nil)
      }
  
      func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return toDoItems.count
      }
  
      func tableView(tableView: UITableView,
          cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
              let cell = tableView.dequeueReusableCellWithIdentifier("cell",
                  forIndexPath: indexPath) as UITableViewCell
              let item = toDoItems[indexPath.row]
              cell.textLabel?.text = item.text
              return cell
      }
  }
  </code></pre>
  
  <p>and my todoItem.swift file : </p>
  
  <pre><code>class todoItem : NSObject{
  
      var text: String
  
      // A Boolean value that determines the completed state of this item.
      var completed: Bool
  
      // Returns a ToDoItem initialized with the given text and default completed value.
      init(text: String) {
          self.text = text
          self.completed = false
      }
  }
  </code></pre>