2010-02-09 59 views
0

我即将创建一个应用程序。如何实现对页面控件的视图

它应该有3个主页。所以我想用PageControl实现这一点。

我创建了3个视图,现在我被困在这个PageControl的实现上。

有没有人有一个很好的教程或示例代码,我可以看看(它也可以是德语)?

感谢, 迈克尔

+0

重复http://stackoverflow.com/questions/1816144/uipagecontrol-help – willcodejavaforfood 2010-02-09 16:42:54

+0

的对不起,没有看到这问题之前: -/ – 2010-02-16 16:02:06

回答

12

下面是如何使用它的一个简单的想法。

PageController.h:

#import <UIKit/UIKit.h> 

@interface PageController : UIViewController { 
    NSArray * views; 
    UIPageControl *pageControl; 
} 

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

- (IBAction) changePage:(id)sender; 
- (void) animateToView:(UIView *)newView; 

@end 

PageController.m:

#import "PageController.h" 

@implementation PageController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    pageControl.numberOfPages = [views count]; 
    pageControl.currentPage = 0; 

    // Either wire this up in Interface Builder or do it here. 
    [pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged]; 
} 

- (IBAction) changePage:(id)sender { 
    UIView * newView = [views objectAtIndex:[pageControl currentPage]]; 
    [self animateToView:newView]; 
} 

- (void) animateToView:(UIView *)newView { 
    // You'd have to implement this yourself 
} 

@end 
+0

在PageController.h中更正:@property(nonatomic,retain)IBOutlet UIPageControl * pageControl; – 2010-12-29 07:02:05

+0

对不起。修复。 – 2010-12-29 20:59:15

+1

好吧没有探测器,科里Kilger :) – 2010-12-31 05:56:13

相关问题