I need some help to implement the function that change the page on pagecontroller. I have a UIPageController
, the number of pages is variable.
Here is my code :
.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.vosveh开发者_运维百科iculeScrollView.frame.size;
NSLog(@"current page %d",pageControlVehiculePossedee.currentPage);
[self.vosvehiculeScrollView scrollRectToVisible:frame animated:YES];*/
[self loadScrollViewWithPage:1];
pageControlUsed = YES;
}
and I get Program received signal: “EXC_BAD_ACCESS”
. How should I implement the changePage method to make it ok? Please help..
Thanks in advance...
I did as follow
- (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];
}
Let me know if you do have any questions.
Regards
精彩评论