gpt4 book ai didi

ios - 尝试将苹果的页面控件示例合并到 Storyboard View Controller 中

转载 作者:行者123 更新时间:2023-11-29 13:23:49 24 4
gpt4 key购买 nike

我有一些图像试图在类似于苹果页面控件示例的 ScrollView 中加载。我的应用程序因错误

而崩溃

'NSInvalidArgumentException', reason: '-[TutorialViewController loadScrollViewWithPage:]: unrecognized selector sent to instance 0x687d0b0'

我想我对此了解得足够多,它告诉我我没有选择器的方法...但我不确定如何修复它!提前谢谢你。

头文件 //教程 View Controller .h #导入

@interface TutorialViewController : UIViewController <UIScrollViewDelegate>
{
// To be used when scrolls originate from the UIPageControl
BOOL pageControlUsed;

int pageNumber;
}


@property (nonatomic, retain) NSArray *iPhoneTutorial;

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;

@property (nonatomic, retain) NSMutableArray *viewControllers;

- (IBAction)changePage:(id)sender;

@end

执行文件

//TutorialViewController.m
#import "TutorialViewController.h"
static NSUInteger kNumberOfPages = 3;

static NSString *NameKey = @"nameKey";
static NSString *ImageKey = @"imageKey";

@interface TutorialViewController (PrivateMethods)
- (void)loadScrollViewWithPage:(int)page;
- (void)scrollViewDidScroll:(UIScrollView *)sender;
@end

@implementation TutorialViewController
@synthesize scrollView, pageControl;

- (void)awakeFromNib
{
// load our data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"iPhoneTutorial" ofType:@"plist"];
self.iPhoneTutorial = [NSArray arrayWithContentsOfFile:path];

// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++)
{
[controllers addObject:[NSNull null]];
}
//self.viewControllers = controllers;
//[controllers release];

// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;

pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;

// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
//
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
}


// load the view nib and initialize the pageNumber ivar
- (id)initWithPageNumber:(int)page
{
pageNumber = page;
return self;
}

- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
if (pageControlUsed)
{
// do nothing - the scroll was initiated from the page control, not the user dragging
return;
}

// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;

// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];

// A possible optimization would be to unload the views+controllers which are no longer visible
}

// At the begin of scroll dragging, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
pageControlUsed = NO;
}

// At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
pageControlUsed = NO;
}

- (IBAction)changePage:(id)sender
{
int page = pageControl.currentPage;

// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];

// update the scroll view to the appropriate page
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];

// Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above.
pageControlUsed = YES;
}


- (void)viewDidLoad

{
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

你必须添加一个

- (void)loadScrollViewWithPage:(int)page

添加 View 的方法

喜欢

switch(page) {
case 0:
myView1 = [[MyView1ViewController alloc] initWithNibName:@"MyView1ViewController" bundle:nil];
[scrollView addSubview: myViewPage1.view];
break;
}

但是Apple Demo“PageControl”在文件PhoneContentViewController.m中有这样一个方法

关于ios - 尝试将苹果的页面控件示例合并到 Storyboard View Controller 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13674032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com