2016-09-23 17 views
0

我想UI表格單元格的索引的數量,並以此爲tittel表格單元格拉布勒文字我的輸出應該是這樣的 輸出如何獲得指數陣列的UITableView的

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 
    } 
+0

什麼不在你的代碼?你有例外嗎?你會得到比預期的結果嗎? –

+0

所有我想要索引號的數組訪問像在JavaScript Array indexOf() – NinjaDeveloper

+3

您正在尋找'indexPath.row' –

回答

1

您可以使用indexPath.row這樣的:

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

的值10直接是表視圖單元格的索引號。

寫作cell.textLabel?.text = "visit#\(indexPath.row)"應該給你預期的結果。