Dissapear UITableViewController от UIViewController - PullRequest
0 голосов
/ 18 ноября 2010

все! У нас проблема с нашим приложением. Есть UITabBarController с 4 вкладками, которые загружаются при запуске. Когда приложение запускается на iPhone 4 еще три дня, на первой вкладке не отображается 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 Ответ

1 голос
/ 18 ноября 2010

Это может быть связано с предупреждением памяти. Вы должны создать контроллер таблицы в viewDidLoad.

Когда появляется предупреждение о памяти, просмотр освобождается. В следующий раз, когда контроллер станет видимым, вы должны заново создать всю иерархию представлений.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...