使用pagecontroller更改页面

时间:2011-10-10 07:21:23

标签: iphone objective-c ios uipagecontrol

我需要一些帮助才能实现更改pagecontroller页面的功能。我有一个UIPageController,页数是可变的。

这是我的代码:

.H **

@property (nonatomic, retain) IBOutlet UIScrollView *vosvehiculeScrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControlVehiculePossedee;
- (IBAction) changePage:(id) sender;
- (void) loadScrollViewWithPage: (int) page;

的.m *

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self getVehicules]; 

    vosvehiculeScrollView.pagingEnabled = YES;

    vosvehiculeScrollView.showsHorizontalScrollIndicator = NO;
    vosvehiculeScrollView.showsVerticalScrollIndicator = NO;
    vosvehiculeScrollView.scrollsToTop = NO;

    pageControlVehiculePossedee.numberOfPages=[vehiculesPossede count];

    pageControlVehiculePossedee.currentPage=0;

    [self loadScrollViewWithPage:0];

    votreVehiculeLabel.text=@"Votre véhicule";
    vehiculesPossedesArray = [[NSMutableArray alloc] initWithObjects:@"Annee modele", @"Transmission",@"Carburant", nil];

}

- (void) loadScrollViewWithPage: (int) page {
    if (page < 0) return;
    if (page >= [vehiculesPossede count]) return;    

    tableViewVehiculesPossedes=[[UITableView alloc] initWithFrame:CGRectMake(3, 80, 315, 171) style:UITableViewStyleGrouped];
    tableViewVehiculesPossedes.bounces=NO;
    tableViewVehiculesPossedes.backgroundColor=[UIColor clearColor];
    [tableViewVehiculesPossedes setDelegate:self];
    [tableViewVehiculesPossedes setDataSource:self];        
    [self.vosvehiculeScrollView addSubview:tableViewVehiculesPossedes];

    nameVehiculeLabel.text=[[vehiculesPossede objectAtIndex:page] valueForKey:@"modele"];

    self.transmissionString=[[vehiculesPossede objectAtIndex:page]valueForKey:@"transmision"];
    self.carburantString=[[vehiculesPossede objectAtIndex:page] valueForKey:@"carburant"];    
    self.anneeModelString=[[vehiculesPossede objectAtIndex:page] valueForKey:@"modele_annee"];
    self.anneeString=[[vehiculesPossede objectAtIndex:page]valueForKey:@"annee"];

    if(page==0){
        NSLog(@"0");  
    }
    else NSLog(@"1");

}


- (IBAction) changePage:(id) sender
{
    NSLog(@"page changed");
   /* CGRect frame;
    frame.origin.x = self.vosvehiculeScrollView.frame.size.width * self.pageControlVehiculePossedee.currentPage;
    frame.origin.y = 0;
    frame.size = self.vosvehiculeScrollView.frame.size;
    NSLog(@"current page %d",pageControlVehiculePossedee.currentPage);
    [self.vosvehiculeScrollView scrollRectToVisible:frame animated:YES];*/

    [self loadScrollViewWithPage:1];
    pageControlUsed = YES;    
}

我得到Program received signal: “EXC_BAD_ACCESS”。我该如何实现changePage方法以使其正常?请帮忙..

提前致谢...

1 个答案:

答案 0 :(得分:0)

我做了如下

- (IBAction)actionBtnNext:(id)sender
   {    
       if (pageNumber == kNumberOfPages-2) {
            pageNumber = kNumberOfPages-2;
       }
       else {
            pageNumber++;
       }

       CGFloat pageWidth = scrollView.frame.size.width*pageNumber;
       [scrollView setContentOffset:CGPointMake(pageWidth,0.0) animated:YES];
 }

如果您有任何疑问,请与我联系。

此致