2010-11-18 7 views
0

tout le monde! Nous avons un problème avec notre application. Il y a UITabBarController avec 4 onglets, qui se charge au démarrage. Lorsque l'application est lancée sur l'iPhone 4 plus de trois jours, le premier onglet n'affiche pas UITableViewController. Mais d'autres onglets fonctionnent bien. Après déchargement de la caisse, tous les onglets sont affichés.Dissimulez UITableViewController de UIViewController

@implementation MyProfileController 

- (id)init { 
     self = [super init]; 
     if (self != nil) 
     { 
     self.tabBarItem = [[UITabBarItem alloc]initWithTitle:JKMyProfile image: 
     [UIImage imageWithCGImage:[[UIImage imageNamed:@"1.png"]CGImage] scale:2.0 orientation:UIImageOrientationUp] 
     tag:0]; 

     UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonSystemItemSave target:self action:@selector(save_clicked:)]; 

     self.navigationItem.rightBarButtonItem = saveButton; 
     [saveButton release]; 

     db = [[DBConnect alloc] init]; 

     table = [[UITableViewController alloc]initWithStyle:UITableViewStyleGrouped]; 
     table.view.backgroundColor = [UIColor clearColor]; 
     table.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0); 
     table.tableView.scrollEnabled = NO; 
     table.tableView.delegate = self; 
     table.tableView.dataSource = self; 

     firstName = [[UITextField alloc] initWithFrame: CGRectMake (25.0, 22.0, 280.0, 50.0)]; 
     firstName.font = [ UIFont boldSystemFontOfSize:16.0]; 
     firstName.placeholder = @"First Name"; 

     [table.view addSubview:firstName]; 

     waitingControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(10, 180, 300, 40)]; 
     [waitingControl insertSegmentWithTitle:@"Boy/Girl" atIndex:0 animated:NO]; 
     [waitingControl insertSegmentWithTitle:@"Twins" atIndex:1 animated:NO]; 

     NSMutableArray *Temp1 = [[[NSMutableArray alloc] init] autorelease]; 
     Temp1 = [db dbqueryselect: 1: @"select WaitingFor from User where Id_user = 1 and WaitingFor > ''"]; 

     if ([Temp1 count] > 0) 
     { 
      if ([[Temp1 objectAtIndex:0] isEqual:@"Boy/Girl"]) 
       waitingControl.selectedSegmentIndex = 0; 
      else 
       waitingControl.selectedSegmentIndex = 1; 
     } 

     [table.view addSubview:waitingControl]; 
     [self.view addSubview:table.view];  
    } 
    return self; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    switch ([indexPath indexAtPosition:0]) 
    { 
     case(0): 
     { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     NSMutableArray *Temp1 = [[[NSMutableArray alloc] init] autorelease]; 

     Temp1 = [db dbqueryselect: 1: @"select FirstName from User where Id_user = 1 and FirstName > ''"]; 

     if ([Temp1 count] > 0) 
      firstName.text = [Temp1 objectAtIndex:0];   
     break; 
     } 
     case (1): 
     { 
      impregDate = [[UILabel alloc] initWithFrame: CGRectMake (200.0, 14.0, 95.0, 20.0)]; 
      impregDate.font = [ UIFont boldSystemFontOfSize:16.0]; 
      impregDate.textColor = [UIColor grayColor]; 
      impregDate.textAlignment = UITextAlignmentRight; 

      NSMutableArray *Temp3 = [[[NSMutableArray alloc] init] autorelease]; 
      Temp3 = [db dbqueryselect: 1: @"select ImpregnationDate from User where Id_user = 1 and ImpregnationDate > ''"]; 

      if ([Temp3 count] > 0) 
      impregDate.text = [NSString stringWithFormat:@"%@",[Temp3 objectAtIndex:0]];  
      else 
      {  
      NSString  *dateString; 
      NSDateFormatter *formatter; 
      formatter = [[NSDateFormatter alloc] init]; 
      [formatter setDateFormat:@"yyyy-MM-dd"]; 
      dateString = [formatter stringFromDate:[NSDate date]]; 
      impregDate.text = dateString; 
      [formatter release]; 
      } 

     cell.textLabel.text = @"Date"; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     [cell addSubview:impregDate]; 

     break; 
    } 
} 
return cell; 
} 

Répondre

1

Il peut être associé à un avertissement de mémoire. Vous devez créer un contrôleur de table au viewDidLoad.

Lorsqu'un avertissement de mémoire se produit, la vue est libérée. La prochaine fois que le contrôleur devient visible, vous devez recréer toute la hiérarchie de vue.

+0

merci beaucoup. Maintenant, notre application fonctionne bien =) –

Questions connexes