2010-11-18 10 views
0

みんな! アプリに問題があります。開始時に読み込まれる4つのタブを持つUITabBarControllerがあります。 iPhone 4でアプリを起動するとさらに3日間、最初のタブにはUITableViewControllerが表示されません。しかし、他のタブはうまくいく。キャッシュからアンロードした後、すべてのタブが表示されます。UIViewControllerからUITableViewControllerを外す

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

答えて

1

メモリ警告に関連する可能性があります。 viewDidLoadにテーブルコントローラを作成する必要があります。

メモリ警告が発生すると、ビューが解放されます。次にコントローラーが表示されたら、すべてのビュー階層を再作成する必要があります。

+0

ありがとうございました。今私たちのアプリはうまくいく=) –

関連する問題