我需要每 5 場比賽增加計數
如果 total_count 為
0,1,2,3,4,5pageNum = 1如果 total_count 為
5,6,7,8,9,10pageNum = 2...
例如。如果 total_count 為 50,則 pageNum = 50/5 = 10
here total_count= 3 但是當我每次重繪 時currentPageNumberVM都在增加,但是為什么呢?
代碼:對于上述邏輯,我撰寫了這樣的代碼currentPageNumberVM = 1 Int((self.paginationData?.result?.total_count ?? 0 - 1) / 5)。但這里total_count保持不變。但是當我重繪 時一直currentPageNumberVM在增加。如何解決這個問題?
var currentPageNumberVM: Int = 1
var isLoadingList: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
self.currentPageNumberVM = 1
self.PagenationMachesService(currentPageNumberVM)
}
private var paginationData = PaginationMaches(dictionary: NSDictionary())
func PagenationMachesService(_ pageNumber: Int) {
let param = ["slug": slugVal ?? "", "page_no": currentPageNumberVM] as [String: Any]
APIReqeustManager.sharedInstance.serviceCall(
param: param as [String: Any], method: .post, url: CommonUrl.get_matches
) { [weak self] (resp) in
if (self?.currentPageNumberVM)! > 1 {
if (PaginationMaches(dictionary: resp.dict as NSDictionary? ?? NSDictionary())?.result?
.matches ?? [Matches]()).count != 0
{
self?.paginationData?.result?.matches! =
PaginationMaches(dictionary: resp.dict as NSDictionary? ?? NSDictionary())?
.result?.matches ?? [Matches]()
} else {
self?.showSingleButtonAlertWithoutAction(title: "NO more data to show")
}
} else {
self?.paginationData = PaginationMaches(
dictionary: resp.dict as NSDictionary? ?? NSDictionary())
}
self?.isLoadingList = false
self?.machesTable.reloadData()
}
}
@objc func refresh() {
self.currentPageNumberVM = 1 Int((self.paginationData?.result?.total_count ?? 0 - 1) / 5)
self.PagenationMachesService(currentPageNumberVM)
}
extension MatchesVC {
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if (scrollView.contentOffset.y scrollView.frame.size.height)
>= scrollView.contentSize.height
{
self.isLoadingList = true
self.refresh()
}
}
}
uj5u.com熱心網友回復:
您正在增加 的值,currentPageNumberVM因為您使用的是“加法賦值運算子” =。
將其更改為“賦值”運算子=,它應該可以正常作業。
self.currentPageNumberVM = 1 Int((self.paginationData?.result?.total_count ?? 0 - 1) / 5)
檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/496746.html
上一篇:如何在Xcode的藍色檔案夾中創建一個新的.storyboard檔案?
下一篇:收藏視圖不更新
