NinjaDeveloper NinjaDeveloper - 1 year ago 84
Swift Question

how to get index number of array in UItableView

I want to get index's number visits array and pass it to table cell Label in tableView how to do that in swift2.0

Visit #1
Visit #2
Visit #3
Visit #4

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
cell.textLabel?.text = "visit#\(visits[indexPath.row])"<-- this line
return cell

Answer Source

You can use indexPath.row like this:

cell.textLabel?.text= "Visit #\(indexPath.row + 1)"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download