开发者

PageController and TableView

开发者 https://www.devze.com 2023-04-12 12:04 出处:网络
I have a page controller and that method pageAction defined like this : -(void)pageAction:(UIPageControl*)control

I have a page controller and that method pageAction defined like this :

-(void)pageAction:(UIPageControl*)control
{       
    NSLog(@"page changed"); 
    [self getVehicules];
    [self.tableViewVehiculesPossedes release];

    int page = pageControlVehiculePossedee.currentPage;
    NSLog(@"page %d", page);
    [self loadScrollViewWithPage:page];

    CGRect frame = pageControlVehiculePossedee.frame;
    frame.origin.x = (vosvehiculeScrollView.frame.size.width * page);
    [vosvehiculeScrollView scrollRectToVisible:frame animated:YES];

    pageControlUsed = YES;
}

Every time I change the page I need to display a tableview with some labels. Here is the code :

- (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];
    [pageControlVehiculePossedee addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];

    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.tag=page;
    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"); 
        self.transmissionString=@"ttt";
    }
    else NSLog(@"1");
}开发者_如何学Go

The problem is that even I put [self.tableViewVehiculesPossedes release]; on the change page method, the tableView appear overlay and the text from labels are overlay. What can I do with the tableview to make it dissapear when a new page will be display?

Please help me..I spent a lot of time with this :|


If I get it correctly I think you should keep an ivar to the table you create with the alloc in loadScrollViewWithPage, and when switching page you should removing it from the view by calling :

[mytableview removeFromSuperview];

And most likely your should take care of releasing it as well as I can't see it in your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号