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 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
}
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 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
}
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 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
}