NinjaDeveloper
NinjaDeveloper

Reputation: 1712

how to get index number of array in UItableView

I want to get index's number of UI table Cell and use it as tittel in table cell lable text my output should look like this output

 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
    }

Upvotes: 0

Views: 360

Answers (2)

rring
rring

Reputation: 11

The value of indexPath.row is directly the index's number of the table view cell.

Writing cell.textLabel?.text = "visit#\(indexPath.row)" should give you the expected result.

Upvotes: 1

Bista
Bista

Reputation: 7903

You can use indexPath.row like this:

cell.textLabel?.text= "Visit #\(indexPath.row + 1)"

Upvotes: 1

Related Questions