-1

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 :):

enter image description here

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))
    })
}
iShaalan
  • 799
  • 2
  • 10
  • 30

1 Answers1

0

It would help to actually see a screenshot of what you're seeing.

Personally, I've noticed (and documented) a bug in Xcode where gaps appear at the top of a UITableView.

enter image description here

.. and you can find the cure for it on this StackOverflow page:

Gap at top of UITableView

Another issue I've seen is that sometimes, even though you've set the DataSource and Delegate for a UITableView it still might not work until you drag'n'drop from the UITableView to the parent in the Storyboard.

enter image description here

Described here: UITableView on storyboard

One final thing, you're not attempting to set the UITableView's data on a background thread, are you..? If so, you'll need to move the code onto the UI thread.

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});

Update

Okay, I've since found out that the issue is actually that the animation doesn't appear properly when moving onto this page.

Ironically, one of my apps does something similar, kicking off an animation when the user goes into the screen.

What I did was deliberately wait for half a second after the viewDidLoad got called, before kicking off my animation. I can't remember why I added this, but perhaps it helps, to give iOS time to finish drawing the screen before starting to animate stuff on it.

My Objective-C did something like this...

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [self doTheAnimationStuff];
});

Perhaps you could try that, and see if the issue still happens ?

Community
  • 1
  • 1
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
  • I have tried to reload the table in a different thread or as you suggested in your answer, but non did work , Can you give my question another look as I have updated it – iShaalan Jun 23 '15 at 14:22
  • So, the issue is actually that your labels (percentage values) *do* get displayed okay, but your animated bars *aren't* appearing ? – Mike Gledhill Jun 23 '15 at 14:32
  • exactly this is the problem – iShaalan Jun 23 '15 at 14:40