我在AppCoda上使用了一个教程来添加一种教程样式的UIPageViewController - 它的工作效果令人惊讶 - 只是我无法通过点击按钮将其删除。
这是我的PageViewController:
#import "startupViewController.h"
#import "SKSlideViewController.h"
#import "APPChildViewController.h"
@interface startupViewController ()
@end
@implementation startupViewController
@synthesize outletWallpaper;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self mymethod];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)mymethod {
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
APPChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (APPChildViewController *)viewControllerAtIndex:(NSUInteger)index {
APPChildViewController *childViewController = [[APPChildViewController alloc] initWithNibName:@"APPChildViewController" bundle:nil];
childViewController.index = index;
return childViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(APPChildViewController *)viewController index];
if (index == 0) {
return nil;
}
// Decrease the index by 1 to return
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(APPChildViewController *)viewController index];
index++;
if (index == 3) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(@"Switching View Controllers...");
SKSlideViewController *slideController=(SKSlideViewController *)[segue destinationViewController];
[slideController setStoryBoardIDForMainController:@"MainVC" leftController:@"LeftVC" rightController:@"RightVC"];
[slideController reloadControllers];
}
@end
此代码将我发送到另一个文件,从那里,我需要删除整个文件。
答案 0 :(得分:0)
我想我在appcoda做了同样的教程,并且有同样的问题!
一个对我有用的解决方案我偶然发现another question:
// Replace deleteVC with your UIPageViewController
[deleteVC willMoveToParentViewController:nil];
[deleteVC.view removeFromSuperview];
[deleteVC removeFromParentViewController];
答案 1 :(得分:0)
var movingIndex = 0
var forwardDirection = false
if selectedIndex == images.count{ //ur pages dataSource You may not need this
movingIndex = selectedIndex - 1
forwardDirection = false
} else {
movingIndex = selectedIndex
forwardDirection = true
}
controllers.remove(at: selectedIndex)
capturedInspectionPhotoView.imagePageController?.dataSource = self
capturedInspectionPhotoView.imagePageController?.setViewControllers([controllers[movingIndex]],
direction: forwardDirection ? .forward : .reverse, animated: true)