Friday 15 August 2014

ios - How to add a two nib UITableViewCell in one Uitableview -


I'm new to iOS development, if in a week you can add two different niche cells, any example Thnx in advance.

You must register 2 nibs

  tableView .registerNib (UINib (NibName: "CELLl", Bundle: zero), forCellReuseIdentifier: "CELL1") tableView.registerNib (UINib (nibName: "CELL2", Bundle: zero), forCellReuseIdentifier: "CELL2")  
< p> and the data source you choose them indexPath

  function tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - & gt; UITableViewCell {give cellname = (indexPath.row% 2 == 0)? "CELL1": "CELL2" Come Sail = tableView.dequeueReusableCellWithIdentifier (cellName, forIndexPath: indexPath) UITableViewCell return as cell}  


What if I want to add more than two new files ...

 code <> i 1 ... 3 {to CellID = "sales" + string (i) tableView.registerNib (UINib (nibName: CellID, bundle: nil), forCellReuseIdentifier: CellID )} in  

and

  function tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - & gt; UITableViewCell {go cellID = (indexPath.row% 3) + 1 cellName = "cell" + String (cellID) cell = tableView.dequeueReusableCellWithIdentifier (cellName, forIndexPath: indexPath) Go UITableViewCell as return cell}  < / Pre> 

Enter image details here


No comments:

Post a Comment