I Am displaying data as shown in this image I want to display the marks or score which I am using as labels. Approx 100s of labels.
I am taking each student details as 1 separate array like:
student1 = [
[test details, test1, test2, test3, test4],
[subject1,100,98,56,78],
[subject2,67,78,89,56],
[subject3,67,56,34,78],
[subject4,56,46,84,38]]
student2 = [[test details, test1, test2, test3, test4],[subject1,100,98,56,78],[subject2,67,78,89,56],[subject3,67,56,34,78],[subject4,56,46,84,38]]
and so on....
these details I want to display in a UITableViewCell
custom cell.
I have written class StudentCustomCell
, which extends UITableViewCell
using for loops
- creating scroll view
- creating background view of scores
- and creating marks labels as my requirement
when I execute the code the same labels/marks of only student 1 were displaying in all the cells.
As I am using only student 1 count in for-in-loop.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SCell", for: indexPath) as! StudentCustomCell
cell.cricketerName.text = studentDetails[indexPath.row][0]
cell.studentImage.image = UIImage(named: studentDetails[indexPath.row][0])
}
return cricketerCell
}
func scoreScrollView(){
scView = UIScrollView(frame: CGRect(x: 0, y: 120, width: cricketView.frame.width, height: 220))
scView.backgroundColor = .white
self.addSubview(scView)
var formatView:UIView!
for i in 0..<(student1[0] as AnyObject).count! {
formatView = UIView()
xAxis = 10
formatView.frame = CGRect(x: 0, y: CGFloat(yAxis), width: 640, height: 40)
if(i % 2 == 0){
formatView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.2132919521)
}else{
formatView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4010595034)
}
for j in 0..<student1.count {
let label = UILabel()
label.text = "\(student1[j][i])"
label.frame = CGRect(x: xAxis, y: CGFloat(yAxis)+5, width: 60, height: 30)
xAxis = xAxis + 65
scView.addSubview(label)
}
yAxis = yAxis + 40
scView.addSubview(formatView)
scrolls.append(scView)
}
scView.contentSize = CGSize(width: xAxis, height: scView.frame.height)
}
test details subject1 subject2 subject3 subject4
test1 100 67 67 56
test2 98 78 56 46
test3 56 89 34 84
test4 78 56 78 38
Am displaying result like above in the cell/row of table view.