как повторить изображения в ячейке таблицы? Есть только 5 изображений, я просто хочу повторить изображения, и он должен содержать только 100 строк - PullRequest
0 голосов
class InfotableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
let myActivityIndicator = UIActivityIndicatorView()

var name = [String]()
var imagearray=[UIImage]()

@IBOutlet weak var table: UITableView!

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 150
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    let cell = table.dequeueReusableCell(withIdentifier: "cell") as! profileTableViewCell
   cell.tableimage.image = nil;
    cell.tableimage.image = imagearray[indexPath.row] as! UIImage
    cell.tablelabel.text = name[indexPath.row] as! String
    self.myActivityIndicator.stopAnimating()
    return cell

}

Ответы [ 2 ]

0 голосов
/ 23 мая 2018
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell1")

    cell?.textLabel?.text = (list1[indexPath.row % list1.count] 

    cell?.imageView?.image = (list1[indexPath.row  % list1.count] 

    return cell!

}
0 голосов
/ 23 мая 2018

Вы должны сделать это,

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 100
}

и это,

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = table.dequeueReusableCell(withIdentifier: "cell") as! profileTableViewCell
    cell.tableimage.image = nil;
    let index = indexPath.row%5
    cell.tableimage.image = imagearray[index] as! UIImage
    cell.tablelabel.text = name[indexPath.row] as! String
    self.myActivityIndicator.stopAnimating()
    return cell

}
...