0

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
    }
4
  • What's not working on your code? Do you get an exception? Do you get a different result than expected? Commented Sep 23, 2016 at 18:02
  • all I want to get index number the array visits like in javascript Array indexOf() Commented Sep 23, 2016 at 18:05
  • 3
    you are looking for indexPath.row Commented Sep 23, 2016 at 18:08
  • Directly use cell.textLabel?.text= "Visit #\(indexPath.row+1)" Commented Sep 23, 2016 at 18:09

2 Answers 2

1

You can use indexPath.row like this:

cell.textLabel?.text= "Visit #\(indexPath.row + 1)"
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.