如何在 tableview 单元格中重复图像?只有 5 张图像,我只想重复这些图像,它应该只包含 100 行
how to repeat the images in a tableview cell?.there are only 5 images i just want to repeat the images and it should contain 100 rows only
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
}
你应该这样做,
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
}
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!
}
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
}
你应该这样做,
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
}
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!
}