Use UITableView In Swift Ios


  • overridefuncprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
  • {
  • ifsegue.identifier == "DetailSegue"
  • {
  • letindexPath = tvCars.indexPathForSelectedRow().row+1
  • ((segue.destinationViewController) as DetailViewController).index=indexPath
  • }
  • }
  • - See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf

  • overridefuncprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
  • {
  • ifsegue.identifier == "DetailSegue"
  • {
  • letindexPath = tvCars.indexPathForSelectedRow().row+1
  • ((segue.destinationViewController) as DetailViewController).index=indexPath
  • }
  • }
  • - See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
    Implement following delegate methods of UITableview in your ViewController.swift file.
    • funcnumberOfSectionsInTableView(tableView: UITableView) ->Int
    • {
    • return 1
    • }
    • functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int
    • {
    • //make sure you use the relevant array sizes
    • returncar.count
    • }
    • functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell
    • {
    • var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCell
    • if(cell == nil)
    • {
    • cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as SampleTableViewCell;
    • }
    • ifUIScreen.mainScreen().bounds.size.height>768
    • {
    • cell.ivWidthConstraint.constant = 100
    • }
    • letstringTitle = carName[indexPath.row] as String //NOT NSString
    • letstrCarName = car[indexPath.row] as String
    • cell.lblTitle.text=stringTitle
    • cell.IvPhoto.image=UIImage(named: strCarName)
    • return cell as SampleTableViewCell
    • }
    - See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
    Implement following delegate methods of UITableview in your ViewController.swift file.
    • funcnumberOfSectionsInTableView(tableView: UITableView) ->Int
    • {
    • return 1
    • }
    • functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int
    • {
    • //make sure you use the relevant array sizes
    • returncar.count
    • }
    • functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell
    • {
    • var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCell
    • if(cell == nil)
    • {
    • cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as SampleTableViewCell;
    • }
    • ifUIScreen.mainScreen().bounds.size.height>768
    • {
    • cell.ivWidthConstraint.constant = 100
    • }
    • letstringTitle = carName[indexPath.row] as String //NOT NSString
    • letstrCarName = car[indexPath.row] as String
    • cell.lblTitle.text=stringTitle
    • cell.IvPhoto.image=UIImage(named: strCarName)
    • return cell as SampleTableViewCell
    • }
    - See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
    Implement following delegate methods of UITableview in your ViewController.swift file.
    • funcnumberOfSectionsInTableView(tableView: UITableView) ->Int
    • {
    • return 1
    • }
    • functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int
    • {
    • //make sure you use the relevant array sizes
    • returncar.count
    • }
    • functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell
    • {
    • var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCell
    • if(cell == nil)
    • {
    • cell = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil)[0] as SampleTableViewCell;
    • }
    • ifUIScreen.mainScreen().bounds.size.height>768
    • {
    • cell.ivWidthConstraint.constant = 100
    • }
    • letstringTitle = carName[indexPath.row] as String //NOT NSString
    • letstrCarName = car[indexPath.row] as String
    • cell.lblTitle.text=stringTitle
    • cell.IvPhoto.image=UIImage(named: strCarName)
    • return cell as SampleTableViewCell
    • }
    - See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf

    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