UITableViewCell, считая от 1 до 50 - PullRequest
0 голосов
/ 28 июня 2018

Я изучаю Swift 4 с Xcode 9 и пытался создать TableView с 50 ячейками. В ячейке 1 "1" в ячейке 2 "2" и т. д.

Вот мой код:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")

        cell.textLabel?.text = String[indexPath.row + 1]
    }
}

Теперь компилятор говорит в этой строке cell.textLabel?.text = String[indexPath.row + 1] «Элемент Instance Member» не может использоваться в строке типа «

Как сделать 50 ячеек с содержанием от 1 до 50?

1 Ответ

0 голосов
/ 29 июня 2018

Вы можете использовать либо:, либо 1001 *

cell.textLabel?.text = String(indexPath.row + 1)

или

cell.textLabel?.text = "\(indexPath.row + 1)"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...