Use UITableView In Swift Ios
overridefuncprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){ifsegue.identifier == "DetailSegue" {letindexPath = tvCars.indexPathForSelectedRow().row+1 ((segue.destinationViewController) as DetailViewController).index=indexPath }}overridefuncprepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){ifsegue.identifier == "DetailSegue" {letindexPath = tvCars.indexPathForSelectedRow().row+1 ((segue.destinationViewController) as DetailViewController).index=indexPath }}
Implement following delegate methods of UITableview in your ViewController.swift file.
- See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
funcnumberOfSectionsInTableView(tableView: UITableView) ->Int{return 1}functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{//make sure you use the relevant array sizesreturncar.count}functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell{var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCellif(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 NSStringletstrCarName = car[indexPath.row] as Stringcell.lblTitle.text=stringTitlecell.IvPhoto.image=UIImage(named: strCarName)return cell as SampleTableViewCell}
Implement following delegate methods of UITableview in your ViewController.swift file.
- See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
funcnumberOfSectionsInTableView(tableView: UITableView) ->Int{return 1}functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{//make sure you use the relevant array sizesreturncar.count}functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell{var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCellif(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 NSStringletstrCarName = car[indexPath.row] as Stringcell.lblTitle.text=stringTitlecell.IvPhoto.image=UIImage(named: strCarName)return cell as SampleTableViewCell}
Implement following delegate methods of UITableview in your ViewController.swift file.
- See more at: http://www.theappguruz.com/blog/ios-table-view-tutorial-using-swift#sthash.pMEnhkgK.dpuf
funcnumberOfSectionsInTableView(tableView: UITableView) ->Int{return 1}functableView(tableView: UITableView, numberOfRowsInSection section: Int) ->Int{//make sure you use the relevant array sizesreturncar.count}functableView(tableView: UITableView, cellForRowAtIndexPathindexPath: NSIndexPath) ->UITableViewCell{var cell : SampleTableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as SampleTableViewCellif(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 NSStringletstrCarName = car[indexPath.row] as Stringcell.lblTitle.text=stringTitlecell.IvPhoto.image=UIImage(named: strCarName)return cell as SampleTableViewCell}