How To Work Use Of UITableView In Swift Ios/Iphone

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
  
    @IBOutlet var tableView: UITableView!
  
    let textCellIdentifier = "TextCell"
  
    let number= ["one", "two","three", "four", "five", "six", "seven", "eight", "nine", "ten"]

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self
    }
  
    // MARK:  UITextFieldDelegate Methods
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
  
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return number.count
    }
  
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as UITableViewCell
      
        let row = indexPath.row
        cell.textLabel?.text = number[row]
      
        return cell
    }
  
    // MARK:  UITableViewDelegate Methods
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
      
        let row = indexPath.row
        println(numer[row])
    }

Popular posts from this blog

How to Use pagination ScrollView in Swift

UISearchBar search text color , background color swift 3

How To Add Multiple Line in Lable in Swift Ios