我有一个页面控制器,该方法pageAction定义如下:
-(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;
}
每次更改页面时,我都需要显示带有一些标签的tableview。这是代码:
- (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");
}
问题在于,即使我将[self.tableViewVehiculesPossedes release];
放在更改页面方法上,tableView也会显示为叠加层,而标签中的文字也会叠加。如果要显示新页面,我该如何处理tableview以使其消失?
请帮助我......我花了很多时间:|
答案 0 :(得分:0)
如果我得到了正确的话,我认为你应该在loadScrollViewWithPage中使用alloc创建一个ivar,当切换页面时,你应该通过调用它来从视图中删除它:
[mytableview removeFromSuperview];
很可能你应该照顾它,以及我在你的代码中看不到它。