TableViewController doesn't flash scroll indicators even if the table is bigger that the view

自作多情 提交于 2020-01-12 13:47:54

问题


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


回答1:


Or more concisely:

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [self.tableView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0];
}



回答2:


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];
}



回答3:


It is not displayed when you show section index titles.

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; 



回答4:


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() 
})


来源:https://stackoverflow.com/questions/3281900/tableviewcontroller-doesnt-flash-scroll-indicators-even-if-the-table-is-bigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!