2010-11-18 11 views
0

alle! Wir haben ein Problem mit unserer App. Es gibt UITabBarController mit 4 Tabs, die beim Start geladen werden. Wenn die App auf dem iPhone 4 weitere drei Tage lang gestartet wird, wird auf der ersten Registerkarte UITableViewController nicht angezeigt. Aber andere Tabs funktionieren gut. Nach dem Entladen von Cashe werden alle Registerkarten angezeigt.Dissapear UITableViewController von 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; 
} 

Antwort

1

Es kann auf Speicher Warnung in Beziehung gesetzt werden. Sie sollten Tabellencontroller in viewDidLoad erstellen.

Wenn eine Speicherwarnung auftritt, wird die Ansicht freigegeben. Wenn der Controller das nächste Mal sichtbar wird, sollten Sie die gesamte Ansichtshierarchie neu erstellen.

+0

vielen Dank. Jetzt funktioniert unsere App gut =) –

Verwandte Themen