16

I've got a weird problem with a TableViewController. In the doc it says that a tableViewController deals also with the method -flashScrollIndicators when the table is "oversized" respect the visible area.

My app consists in 3 nav controller loaded in a tab controller. Each nav controller has as root view controller a subclass of a table view controller. Each "model" is populated from a plist file, that loads its contents into an array in the -viewDIdLoad, later everything is passed to the table. Everything is loaded programmatically no IB.

I've found out in my app that when it loads the first view (a nav controller with a table view controller as root) the scroll bar isn't flashing even if the number of cell it's great enough. If I choose another tab, that loads another nav controller (with a t.v.c. as root) scroll bar isn't shown again. When I press the tab corresponding to the first nav controller loaded the scrollbar flashes.

So I've tried to make it flash programmatically but no way, the code seems simple:

[self.tableView flashScrollIndicators];

I've tried to put it almost everywhere. First in the -viewDidLoad (As suggested in the doc), then in viewDidAppear and in -viewWillAppear. Also tried use that code tring to cast the view of the t.v.c. as a table view.

[((UITableView*)self.view) flashScrollIndicators];

..without result.

I've started looking at Apple sample and I've found that in Apple's table view custom sample (the one with different times) scroll bar doesn't flash also there. Tested both on sim and device.

Is a bug?, is there a correct way to show it programmatically? Can someone help me? Regards, Andrea

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • It should just work when you call `flashScrollIndicators`, but I can confirm it can be extremely frustrating to pinpoint the best place to put things like this. There's no penalty in calling it twice btw so just litter your project with this call ;-) – mvds Jul 19 '10 at 14:32
  • Hi mvds unfortunately it doesn't work even if I try to call by myself in -viewDidLoad , -viewWillAppear, -viewDidAppear. – Andrea Jul 19 '10 at 17:24
  • Did you check that self.tableView is not nil? Did you try a -reloadData first? – Ortwin Gentz Jul 20 '10 at 09:02
  • Well, Ortwin...THANKS. Of course the Table wasn't nil. Using reloadData everything works. Could you write as an answer? so we could solve it. – Andrea Jul 27 '10 at 17:30

4 Answers4

41

Or more concisely:

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [self.tableView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0];
}
matm
  • 7,059
  • 5
  • 36
  • 50
Hilton Campbell
  • 6,065
  • 3
  • 47
  • 79
  • This works!!! Thanks! I use this in [acaniChat](https://github.com/acani/acaniChat) to flash the scroll indicators of the `UITableView *chatContent` when the `UIViewController *chatViewController` appears. – ma11hew28 Apr 05 '11 at 17:55
  • edited, forgetting to call implementation of the super class is the bad habit ;) – matm Jun 05 '13 at 15:36
  • I was using just [self.scrollView flashScrollIndicators]; which did not work in a particular case, whereas your performSelector solution does work great. Thanks. – Custom Bonbons Mar 25 '14 at 12:14
  • I was having this same issue, I tried the delayed performSelector and noticed something very interesting. My tableView is presented in a UIPopover that is invoked by a user tap. If I hold my finger down after the tap that brings up the popover, the scroll indicators never flash. If I release quick enough (before my delayed performSelector), the indicators flash. So there is something going on to prevent them from flashing if the user keeps holding their finger down while the tableView is being cranked up. – Swany Apr 09 '14 at 22:25
  • Wow, it really works!!, But for me I am using UIPageViewController where in the UIViewController has a scrollview flashing the scroll indicator doesnt works, I tried using it inside viewWillAppear and viewDidAppear. Thanks for this awesome fix. But Im curious what is the reason behind this. – otakuProgrammer Sep 29 '14 at 05:28
  • its also working without perform selector in viewDidAppear method. **[self. tableView flashScrollIndicators];** – RaviM Feb 24 '16 at 13:14
12

I had exactly the same problem. I got around it in the end by putting a delayed selector in the viewDidAppear: method. Weirdly, I can set it to 0 seconds and it still works fine.

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    [self performSelector:@selector(flashTableScrollIndicators) withObject:nil afterDelay:0.0];
}

- (void)flashTableScrollIndicators
{
    [self.tableView flashScrollIndicators];
}
jowie
  • 8,028
  • 8
  • 55
  • 94
  • That's the solution I was looking for.THX. Regards, Andrea – Andrea Aug 19 '10 at 06:34
  • 2
    you can also do it like this `[self.tableView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0.0];` – matm Jun 05 '13 at 15:34
3

It is not displayed when you show section index titles.

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; 
Pang
  • 9,564
  • 146
  • 81
  • 122
netshark1000
  • 7,245
  • 9
  • 59
  • 116
0

My solution was to send the "flashScrollIndicators()" message with a slight delay using "dispatch_after":

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.4 * Double(NSEC_PER_SEC)))

dispatch_after(delayTime, dispatch_get_main_queue(), 
{ () -> Void in 
    myScrollView.flashScrollIndicators() 
})
lucamegh
  • 527
  • 6
  • 16