2011-10-10 61 views
0

我有一個頁面控制器和這樣定義的方法pageAction:的PageController和TableView中

-(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; 
} 

每次我改變我需要顯示一些標籤一個實現代碼如下頁面。下面是代碼:

- (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]; 

    [email protected]"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"); 
     [email protected]"ttt"; 
    } 
    else NSLog(@"1"); 
} 

的問題是,即使我把[self.tableViewVehiculesPossedes release];上的改變頁面的方法,在出現的tableView覆蓋和標籤文本被重疊。我可以用tableview做些什麼來使它在新頁面顯示時消失?

請幫助我..我花了很多時間:

回答

0

如果我沒有得到它,我認爲你應該讓伊娃你在loadScrollViewWithPage的ALLOC創建表,並切換頁面時,你應該通過調用視圖中刪除了它:

[mytableview removeFromSuperview]; 

而且最可能你應該照顧釋放它,以及我在你的代碼中看不到它。