In a I am using several UITableView in my app. Some of them contain several rows, while some have two three only. What I need is: if the table contains several rows, then the scrollbar should be visible before the user even drags the table down. Or in another way, is it possible to make scrollbar visible always??
Asked
Active
Viewed 1.3k times
12
-
UITableView's scrollBar only visible when your content it larger then height of your UITableView.. – iPatel Mar 25 '14 at 04:56
-
Yes I know that. In that case only, I want the scroll indicator to show always. – Shradha Mar 25 '14 at 04:57
3 Answers
20
You can flash them but there isn't an option to make them always visible:
[ScrollView flashScrollIndicators];
UITableView is a subclass of UIScrollView,So you can use it directly with it
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView performSelector:@selector(flashScrollIndicators) withObject:nil afterDelay:0];
}
Check out for more info : UIScrollView - showing the scroll bar
Swift:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tableView.flashScrollIndicators()
}
-
-
1i tried doing [[self.table superclass] flashScrollIndicators].. but it does not work.. – Shradha Mar 25 '14 at 05:02
-
UITableView is a subclass of UIScrollView, so you should just use the table view directly. – Kumar KL Mar 25 '14 at 05:06
14
Swift 3.0
1) Timer
var timerForShowScrollIndicator: Timer?
2) Methods
/// Show always scroll indicator in table view
func showScrollIndicatorsInContacts() {
UIView.animate(withDuration: 0.001) {
self.tableView.flashScrollIndicators()
}
}
/// Start timer for always show scroll indicator in table view
func startTimerForShowScrollIndicator() {
self.timerForShowScrollIndicator = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.showScrollIndicatorsInContacts), userInfo: nil, repeats: true)
}
/// Stop timer for always show scroll indicator in table view
func stopTimerForShowScrollIndicator() {
self.timerForShowScrollIndicator?.invalidate()
self.timerForShowScrollIndicator = nil
}
3) Use
startTimerForShowScrollIndicator in viewDidAppear
stopTimerForShowScrollIndicator in viewDidDisappear

ZAV
- 371
- 4
- 12
1
var timerForIndicatore:Timer?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
showIndicator()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
deinitializeIndicator()
}
@objc func startContinuosShowingIndicator() {
UIView.animate(withDuration: 0.0001) {
self.deviceListTableView.flashScrollIndicators()
}
}
func showIndicator() {
self.timerForIndicatore = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.startContinuosShowingIndicator), userInfo: nil, repeats: true)
}
func deinitializeIndicator() {
self.timerForIndicatore?.invalidate()
self.timerForIndicatore = nil
}

Yudhisther Aryan
- 11
- 1
-
You might consider adding some description/explaination on why and how this solves his problem – Olympiloutre Jul 10 '20 at 09:19
-
@yudhisther just sharing my understanding to the code. The process is, having a timer that repeatedly call the `UIScrollView.flashScrollIndicators()` every 300ms. Hope this answers your question – lexlab Feb 26 '21 at 02:07