Swift 表视图上的 Pulltorefresh 可能导致线程 1 的原因:EXC_BAD_ACCESS(代码=1,地址=0x53178d8ac)来自提供的代码
Swift Pulltorefresh on tableview what might be causing Thread 1: EXC_BAD_ACCESS (code=1, address=0x53178d8ac) from provided code
最近在大约 10-30 次拉动刷新后测试我的主页视图控制器上的拉动刷新功能时,控制器有时会因线程 1 崩溃:EXC_BAD_ACCESS(代码=1,地址=0x53178d8ac)
这是我在下拉刷新功能中的代码
//this function is for the tableview controllers pull to refresh
@objc func refreshWasPulled(){
//check if this is for the trending screen
if isRepresentingExplorePageClick == true {
DispatchQueue.main.async {
self.refreshControl.endRefreshing()
}
}else if isRepresentingFollowingData == false {
//call the API
HomepageAPInetwork.userTrendingContent(accessKey: accessKey, completionHandler: { posts in
//set the posts
self.followingPosts.removeAll()
self.followingPosts = posts
//call the main thread
DispatchQueue.main.async {
//reset the estimatedrowheight
self.Tableview.estimatedRowHeight = 600
//set the rowheight to use the automatic dimension
self.Tableview.rowHeight = UITableView.automaticDimension
self.refreshControl.endRefreshing()
//reload the data
//begin tableview updates
self.Tableview.reloadData()
}
})
}else if isRepresentingFollowingData == true {
HomepageAPInetwork.userFollowingContent(accessKey: accessKey, completionHandler: {posts in
self.followingPosts.removeAll()
//set the posts
self.followingPosts = posts
//call the main thread
DispatchQueue.main.async {
//reset the estimatedrowheight
self.Tableview.estimatedRowHeight = 600
//set the rowheight to use the automatic dimension
self.Tableview.rowHeight = UITableView.automaticDimension
//end the refresh control
self.refreshControl.endRefreshing()
//reload the data
self.Tableview.reloadData()
}
})
}
因为我在我的主页上使用了自定义的 Scrolltorow 功能,所以它实际上搞乱了刷新,我就是这样做来解决这个问题的。
之前
self.refreshControl.endRefreshing()
之后
if self.refreshControl.isRefreshing == true {
self.refreshControl.endRefreshing()
}
最近在大约 10-30 次拉动刷新后测试我的主页视图控制器上的拉动刷新功能时,控制器有时会因线程 1 崩溃:EXC_BAD_ACCESS(代码=1,地址=0x53178d8ac)
这是我在下拉刷新功能中的代码
//this function is for the tableview controllers pull to refresh
@objc func refreshWasPulled(){
//check if this is for the trending screen
if isRepresentingExplorePageClick == true {
DispatchQueue.main.async {
self.refreshControl.endRefreshing()
}
}else if isRepresentingFollowingData == false {
//call the API
HomepageAPInetwork.userTrendingContent(accessKey: accessKey, completionHandler: { posts in
//set the posts
self.followingPosts.removeAll()
self.followingPosts = posts
//call the main thread
DispatchQueue.main.async {
//reset the estimatedrowheight
self.Tableview.estimatedRowHeight = 600
//set the rowheight to use the automatic dimension
self.Tableview.rowHeight = UITableView.automaticDimension
self.refreshControl.endRefreshing()
//reload the data
//begin tableview updates
self.Tableview.reloadData()
}
})
}else if isRepresentingFollowingData == true {
HomepageAPInetwork.userFollowingContent(accessKey: accessKey, completionHandler: {posts in
self.followingPosts.removeAll()
//set the posts
self.followingPosts = posts
//call the main thread
DispatchQueue.main.async {
//reset the estimatedrowheight
self.Tableview.estimatedRowHeight = 600
//set the rowheight to use the automatic dimension
self.Tableview.rowHeight = UITableView.automaticDimension
//end the refresh control
self.refreshControl.endRefreshing()
//reload the data
self.Tableview.reloadData()
}
})
}
因为我在我的主页上使用了自定义的 Scrolltorow 功能,所以它实际上搞乱了刷新,我就是这样做来解决这个问题的。
之前
self.refreshControl.endRefreshing()
之后
if self.refreshControl.isRefreshing == true {
self.refreshControl.endRefreshing()
}