json值是相同的,那么为什么在swift中的tableview在分页上进行计数
如果total_count是0,1,2,3,4,5
,则我需要增加每5个匹配的计数
,然后pagenum = 1
如果total_count是
5,6,7,8,9,10
然后Pagenum = 2 ...
对于例如,如果total_count为50,则pagenum = 50/5 = 10
这里
在 我已经编写了这样的代码currentPagenumbervm + = 1 + int((self.paginationdata?result?.total_count ?? 0-1) / 5) / 5)< / code>。但是这里
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()
}
}
}
I need to increase count for every 5 matches
if total_count is
0,1,2,3,4,5
then pageNum = 1if total_count is
5,6,7,8,9,10
then pageNum = 2...
for eg. if total_count is 50 then pageNum = 50/5 = 10
here total_count
= 3 but when I refresh each time currentPageNumberVM
is increasing, but why?
code: for above logic i have written code like this currentPageNumberVM += 1 + Int((self.paginationData?.result?.total_count ?? 0 - 1) / 5)
. But here total_count
stays the same. But when I refresh currentPageNumberVM
is increasing all the time. How to solve this issue?
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()
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在增加
CurrentPageNumberVM
的值,因为您正在使用“添加分配运算符”+=
。将其更改为“分配”操作员
=
,它应该正常工作。文档
You are increasing the value of
currentPageNumberVM
because you are using the "addition assignment operator"+=
.Change it to the "assignment" operator
=
and it should work fine.documentation