I have a 'UIViewContrller', a segmentedcontrol and 'UITableView' in 'UIViewController'. Each tab [segment] will show different in the table, My approach was using the same table and when the segment is clicked I will repopulate the table with the new data. Every thing goes fine but when I click the second tab the cells are shown [with some data populated] but not all of them. when I scroll down I get all data shown correctly.
I am not sure which code to post that will help you get the problem so please ask for any.
Here is some code snippet :
func segmentChange(){
//self.populateProgressTable(tableView, indexPath: NSIndexPath())
tableView.reloadData()
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//control segment is selected
if (segmentedControl.selectedSegmentIndex == 0){
return populateControlTable(tableView, indexPath: indexPath)
}else{
//progress segment is selected
return populateProgressTable(tableView, indexPath: indexPath)
}
}
func populateProgressTable(table: UITableView ,indexPath: NSIndexPath) -> UITableViewCell{
var cell:ProgressCell = tableView.dequeueReusableCellWithIdentifier("ProgressCell") as! ProgressCell
cell.initWithCourseName("science",courseProgress: 34, thirdLevelProgress: 94, fourthLevelProgress: 12, fifthLevelProgress: 99)
return cell
}
UPDATE here is a screenshot it is in Arabic :):
So when the table first shown the percentage is updated correctly but the bars are not shown, It might be helpful to mention that I am animating the bars as you can see in this code:
func makeProgressAnimations(container: UIView , bar: UIView ,color: UIColor ,persentage: Double ,margin:Int ){
var x = Int(container.bounds.width) - margin
var y = margin
var width = ((Double(container.frame.width) - 4) * ( -(persentage/100)))
var hieght = (Int(container.frame.height) - (margin * 2))
UIView.animateWithDuration( 1 , animations: {
bar.frame = CGRectMake(CGFloat(x) , CGFloat(y),CGFloat(width),CGFloat(hieght))
})
}