swift


How to detect when UITableView header scrolls?


I currently have a UITableView whose HeaderView is a UIScrollView. I am using this as a sort of carousel that displays constantly rotating information triggered to move on a timer every two seconds. What I am trying to do is detect when the user has moved the scroll view on their own. Here is the code I have to handle the ScrollView movement right now.
override func viewDidLoad() {
var myTimer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: true)
}
func runTimedCode() {
var itemCount = newsArray.count // how many items are in the news reel
if currentPage < itemCount {
let newX = CGFloat(currentPage) * self.view.frame.width // calculate next page position
featuredScrollView.setContentOffset(CGPoint(x: newX, y: 0), animated: true)
currentPage += 1
} else {
// end of items
currentPage = 0
let newX = CGFloat(currentPage) * self.view.frame.width // calculate next page position
print("new x = \(newX)")
featuredScrollView.setContentOffset(CGPoint(x: newX, y: 0), animated: true)
}
}
However the scrollViewDidScroll function is only called when the tableview is moved. Is there any way to detect when the ScrollView above the tableView is scrolled? I'm completely stuck on this any help is appreciated. Thanks!
First, make sure that you have the delegate set up so that your view controller gets events from both the scroll view and the table view.
Next, keep references to make sure that you can distinguish the two views.
Finally, check which reference is triggering the viewdidscroll function and do your code there.
let view1:UIScrollView!
let view2:UITableView!
view1.delegate = self
view2.delegate = self
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == view1 {
// Do something
}
if scrollView == view2 {
// Do something
}
}

Related Links

Prepping info for a data grid in Swift
How to convert CGWindowID to CFTypeRef?
How to hide dots on last view of UIPageViewController SWIFT
custom console log in swift [duplicate]
UI Test Success but never Runs on Mac
How to fake Realm Results for tests
Swift wait until dataTaskWithRequest has finished to call the return [duplicate]
Making a GIF from images using Swift (macOS)
NSTableView cells ontop of header
CoreData/TableView - Ambiguous use of 'subscript'
Saving the users username to the firebase database using swift in Xcode
Swift: Help finding inconsistencies that are making my app crash [duplicate]
Correct release NSViewController embedded in subviews
How to fetch stickers collection from iMessage?
Adding constraint (programmatically) for NSView never returns
Java BigDecimal in Swift

Categories

HOME
dotnetrdf
pug
websphere
decorator
docker-swarm
zend-framework2
checksum
laravel-4
xtext
apiconnect
urlencode
i2c
vuex
eclipse-cdt
wicket
outlook-web-addins
dryioc
nuxt.js
python-unicode
chocolatey
ip-camera
os161
richfaces
azure-servicebus-queues
iis-10
mef2
chrome-native-messaging
pygooglechart
entity-system
division
large-data
superpowered
autocompletetextview
liquid-xml
dql
active-model-serializers
cross-entropy
tango
spring-bean
homekit
dojox.grid.datagrid
rapidweaver
ajp
ideone
tcserver
adler32
bettercms
iron.io
atlassian-crowd
glkit
wcf-ria-services
zurb-foundation-apps
pax-web
qregexp
image-editing
asp.net-mvc-2
portfolio
loopj
windows-vista
matcaffe
jericho-html-parser
subresource-integrity
jython-2.7
low-level
pisa
obfuscar
libsndfile
em
alertifyjs
jstack
db4o
edit-in-place
healthvault
exiv2
html-form-post
haskell-platform
localtime
ienumerator
multiple-conditions
shiva3d
resgen
qss
qtgui
process-monitor
feof
responsetext
hinstance
handwriting
scalaxb
for-xml-path
ets
audiostreamer
yajl
external-assemblies
plinq
act
database-diagramming
hardware-infrastructure
self-reference
divx

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App