Add UITableView to UIView.Add custom cells, bind custom cell classes and implement the delegates -UITableviewDelegate and UITableViewDataSource.
case 1: two custom cells in table view
func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: CustomCell! if indexPath.row == 0{ cell = tableView.dequeueReusableCellWithIdentifier("Cell1ID", forIndexPath: indexPath) as CustomCell //set cell2 } if indexPath.row >= 1{ cell = tableView.dequeueReusableCellWithIdentifier("Cell2ID", forIndexPath: indexPath) as CustomCell let cons = aArray[indexPath.row - 1] // set cell2 } return cell }
case 2: alternative display of user cells (i.e. using uisegment control)
var CellIdentifier: String = "Cell1ID" func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { if (CellIdentifier == "Cell1ID") { let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier)! as! FirstTableViewCell //additional code return cell } else { let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier)! as! SecondTableViewReportsCell //Additional code return cell } }
case 3: Alternative custom cells (i.e. odd evens)
var CellIdentifier: String = "Cell1ID" func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell: CustomCell! if (indexPath.row % 2 == 0) { let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier)! as! FirstTableViewCell } else { let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier)! as! SecondTableViewCell } return cell }
Alvin george
source share