为什么我的方法调用两次?
我有一个方法在我的页面视图控制器类,这意味着产生一组数字一次,但相反,似乎因为某种原因两次激发?谁能告诉我为什么它的两次发射?为什么我的方法调用两次?
这是控制台火灾
发生了什么,为什么不是它的工作像它应注意什么?
我希望我的页面视图控制器循环,因为用户向前滚动,而我有五个不同的数字,不断循序渐进,但不循环,他们只是无限增加。
刷卡向后方法
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
swipeTotal = swipeTotal - 1;
if (swipeTotal > 4) {
firstFive = true;
// NSLog(@"First Five Passed");
}else{
firstFive = false;
// NSLog(@"First Five False");
}
// NSLog(@"Swipe Total is %d",swipeTotal);
if (currentIndex == 0) {
swipeContent1 = swipeTotal;
swipeContent2 = swipeTotal + 1;
swipeContent3 = swipeTotal + 2;
swipeContent4 = swipeTotal - 2;
swipeContent5 = swipeTotal - 1;
}
if (currentIndex == 1) {
swipeContent1 = swipeTotal - 1;
swipeContent2 = swipeTotal;
swipeContent3 = swipeTotal + 1;
swipeContent4 = swipeTotal + 2;
swipeContent5 = swipeTotal - 2;
}
if (currentIndex == 2) {
swipeContent1 = swipeTotal - 2;
swipeContent2 = swipeTotal - 1;
swipeContent3 = swipeTotal;
swipeContent4 = swipeTotal + 1;
swipeContent5 = swipeTotal + 2;
}
if (currentIndex == 3) {
swipeContent1 = swipeTotal + 2;
swipeContent2 = swipeTotal - 2;
swipeContent3 = swipeTotal - 1;
swipeContent4 = swipeTotal;
swipeContent5 = swipeTotal + 1;
}
if (currentIndex == 4) {
swipeContent1 = swipeTotal + 1;
swipeContent2 = swipeTotal + 2;
swipeContent3 = swipeTotal - 2;
swipeContent4 = swipeTotal - 1;
swipeContent5 = swipeTotal;
}
if (firstFive == true) {
if (currentIndex == 0) {
currentIndex = 4;
}else{
--currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
}
}else{
if (currentIndex > 0)
{
return [myViewControllers objectAtIndex:currentIndex-1];
// return the previous viewcontroller
} else
{
return nil;
// do nothing
}
}
/*
content1 = [users objectAtIndex:swipeContent1];
content2 = [users objectAtIndex:swipeContent2];
content3 = [users objectAtIndex:swipeContent3];
content4 = [users objectAtIndex:swipeContent4];
content5 = [users objectAtIndex:swipeContent5]; */
NSLog(@"Content 1 = %d",swipeContent1);
NSLog(@"Content 2 = %d",swipeContent2);
NSLog(@"Content 3 = %d",swipeContent3);
NSLog(@"Content 4 = %d",swipeContent4);
NSLog(@"Content 5 = %d",swipeContent5);
return [myViewControllers objectAtIndex:currentIndex];
}
刷卡转发方法
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
if (swipeTotal > 4) {
firstFive = true;
// NSLog(@"First Five Passed");
}else{
firstFive = false;
// NSLog(@"First Five False");
}
// NSLog(@"Swipe Total is %d",swipeTotal);
++currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
swipeTotal = swipeTotal + 1;
if (currentIndex == 0) {
swipeContent1 = swipeTotal;
swipeContent2 = swipeTotal + 1;
swipeContent3 = swipeTotal + 2;
swipeContent4 = swipeTotal - 2;
swipeContent5 = swipeTotal - 1;
} else if (currentIndex == 1) {
swipeContent1 = swipeTotal - 1;
swipeContent2 = swipeTotal;
swipeContent3 = swipeTotal + 1;
swipeContent4 = swipeTotal + 2;
swipeContent5 = swipeTotal - 2;
} else if (currentIndex == 2) {
swipeContent1 = swipeTotal - 2;
swipeContent2 = swipeTotal - 1;
swipeContent3 = swipeTotal;
swipeContent4 = swipeTotal + 1;
swipeContent5 = swipeTotal + 2;
} else if (currentIndex == 3) {
swipeContent1 = swipeTotal + 2;
swipeContent2 = swipeTotal - 2;
swipeContent3 = swipeTotal - 1;
swipeContent4 = swipeTotal;
swipeContent5 = swipeTotal + 1;
} else if (currentIndex == 4) {
swipeContent1 = swipeTotal + 1;
swipeContent2 = swipeTotal + 2;
swipeContent3 = swipeTotal - 2;
swipeContent4 = swipeTotal - 1;
swipeContent5 = swipeTotal;
}
NSLog(@"Content 1 = %d",swipeContent1);
NSLog(@"Content 2 = %d",swipeContent2);
NSLog(@"Content 3 = %d",swipeContent3);
NSLog(@"Content 4 = %d",swipeContent4);
NSLog(@"Content 5 = %d",swipeContent5);
return [myViewControllers objectAtIndex:currentIndex];
}
回答:
我认为你UIPageViewController
需要3控制器(一般),以便能够正确显示其内容:
- 主要可见控制器
- 上一个
- 下一个
此以前和下一个是部分可见的部分时,您的滚动控制器。
因此,您的2种方法不是针对滑动方向分别调用的,而是在您每次滚动控制器时调用。因此,您的滑动内容会被评估两次。
以上是 为什么我的方法调用两次? 的全部内容, 来源链接: utcz.com/qa/258927.html