Ios5 使用Apple'学习UIPageControl;s";“页面控制”;示例,需要修改以添加我的视图控制器的帮助吗
使用Apple“PageControl”作为模板。我想知道如何修改代码以使用我的故事板中的视图控制器。让我们调用视图控制器,一个,两个,三个。该示例对视图控制器使用NULL 完整代码如下: 提前谢谢 -保罗Ios5 使用Apple'学习UIPageControl;s";“页面控制”;示例,需要修改以添加我的视图控制器的帮助吗,ios5,uiviewcontroller,xcode4.2,uipagecontrol,Ios5,Uiviewcontroller,Xcode4.2,Uipagecontrol,使用Apple“PageControl”作为模板。我想知道如何修改代码以使用我的故事板中的视图控制器。让我们调用视图控制器,一个,两个,三个。该示例对视图控制器使用NULL 完整代码如下: 提前谢谢 -保罗 - (void)awakeFromNib { // load our data from a plist file inside our app bundle NSString *path = [[NSBundle mainBundle] pathForResource:@"
- (void)awakeFromNib
{
// load our data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"content_iPhone" ofType:@"plist"];
self.contentList = [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 = 1;
// 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];
}
- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;
// replace the placeholder if necessary
MyViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[MyViewController alloc] initWithPageNumber:page];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// add the controller's view to the scroll view
if (controller.view.superview == nil)
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
NSDictionary *numberItem = [self.contentList objectAtIndex:page];
controller.numberImage.image = [UIImage imageNamed:[numberItem valueForKey:ImageKey]];
controller.numberTitle.text = [numberItem valueForKey:NameKey];
}
}
-(void)从NIB唤醒
{
//从应用程序包中的plist文件加载数据
NSString*path=[[NSBundle mainBundle]pathForResource:@“内容”类型:@“plist”];
self.contentList=[NSArray arrayWithContentsOfFile:path];
//视图控制器是惰性创建的
//同时,加载带有占位符的数组,占位符将根据需要替换
NSMutableArray*控制器=[[NSMutableArray alloc]init];
for(无符号i=0;i=kNumberOfPages)
返回;
//如有必要,请替换占位符
MyViewController*controller=[ViewController对象索引:页];
如果((NSNull*)控制器==[NSNull])
{
控制器=[[MyViewController alloc]initWithPageNumber:page];
[viewControllers replaceObjectAtIndex:page with Object:controller];
[控制器释放];
}
//将控制器视图添加到滚动视图
if(controller.view.superview==nil)
{
CGRect frame=scrollView.frame;
frame.origin.x=frame.size.width*页;
frame.origin.y=0;
controller.view.frame=frame;
[scrollView添加子视图:controller.view];
NSDictionary*numberItem=[self.contentList objectAtIndex:page];
controller.numberImage.image=[UIImage ImageName:[numberItem valueForKey:ImageKey]];
controller.numberTitle.text=[numberItem valueForKey:NameKey];
}
}
我不认为故事板中的控制器与.h和.m文件有内在联系。我认为您必须为它们中的每一个创建XIB,然后加载它们。我不认为故事板中的控制器与.h和.m文件有内在的联系。我认为您必须为它们中的每一个创建XIB,并加载它们。