2012-06-23 4 views
0

У меня есть UITableView, который заполняется данными ядра. Теперь, когда я нажимаю на ячейку, это подталкивает меня к другому представлению, где я могу редактировать данные, находящиеся в этом конкретном индексе, когда я возвращаюсь, система либо сбой, либо не загружает изменения на ярлыки, любые идеи ? Код нижеUILabels NOT Updating

-(void)viewWillAppear:(BOOL)animated 
{  
    searchCriteria = [[NSMutableString alloc] initWithString:@"clientName"]; 
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientName" ascending:YES]; 
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 
    [fetchRequest setSortDescriptors:sortDescriptors]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext]; 
    [fetchRequest setEntity:entity];  
    fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; 

    [self.clientTableView reloadData]; 
    [super viewWillAppear:animated];  
} 

-(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]; 
    } 

    Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)]; 
    clientNameLabel.tag = 1; 
    clientNameLabel.backgroundColor = [UIColor clearColor]; 
    clientNameLabel.textColor = [UIColor whiteColor]; 
    clientNameLabel.font = [UIFont boldSystemFontOfSize:13]; 
    clientNameLabel.text = client.clientName; 
    [cell.contentView addSubview:clientNameLabel]; 

    clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)]; 
    clientAccountNumberLabel.tag = 2; 
    clientAccountNumberLabel.textColor = [UIColor whiteColor]; 
    clientAccountNumberLabel.backgroundColor = [UIColor clearColor]; 
    clientAccountNumberLabel.font = [UIFont boldSystemFontOfSize:13]; 
    clientAccountNumberLabel.text = client.clientAccountNumber; 
    [cell.contentView addSubview:clientAccountNumberLabel]; 

    clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)]; 
    clientTelephoneNumberLabel.tag = 3; 
    clientTelephoneNumberLabel.textColor = [UIColor whiteColor]; 
    clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor]; 
    clientTelephoneNumberLabel.font = [UIFont boldSystemFontOfSize:13]; 
    [cell.contentView addSubview:clientTelephoneNumberLabel]; 

    addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
    addressLine1Label.tag = 4; 
    addressLine1Label.textColor = [UIColor whiteColor]; 
    addressLine1Label.backgroundColor = [UIColor clearColor]; 
    addressLine1Label.font = [UIFont boldSystemFontOfSize:13]; 
    addressLine1Label.text = client.addressLine1; 
    [cell.contentView addSubview:addressLine1Label]; 

    addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
    addressLine2Label.tag = 5; 
    addressLine2Label.textColor = [UIColor whiteColor]; 
    addressLine2Label.backgroundColor = [UIColor clearColor]; 
    addressLine2Label.text = client.addressLine2; 
    addressLine2Label.font = [UIFont boldSystemFontOfSize:13]; 
    [cell.contentView addSubview:addressLine2Label]; 

    addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
    addressLine3Label.tag = 6; 
    addressLine3Label.textColor = [UIColor whiteColor]; 
    addressLine3Label.backgroundColor = [UIColor clearColor]; 
    addressLine3Label.font = [UIFont boldSystemFontOfSize:13]; 
    addressLine3Label.text = client.addressLine3; 
    [cell.contentView addSubview:addressLine3Label]; 

    addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
    addressLine4Label.tag = 7; 
    addressLine4Label.textColor = [UIColor whiteColor]; 
    addressLine4Label.backgroundColor = [UIColor clearColor]; 
    addressLine4Label.font = [UIFont boldSystemFontOfSize:13]; 
    addressLine4Label.text = client.addressLine4; 
    [cell.contentView addSubview:addressLine4Label]; 

    return cell; 
} 

краш-Логи заключаются в следующем:

2012-06-23 17:08:05.541 iSalesForce[11773:15803] no object at index 1 in section at index 0 

И какой-то другой код, который вы могли бы найти полезными:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [fetchedObjects count]; 
} 

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 70.0; 
} 
+1

Т.Л. Д-р - каков фактический крах, который вы получаете? показать обратную линию. –

+0

покажите код для вашего метода '' numberOfSectionsInTableView: '. –

+0

Не помещайте эти вещи в комментарии, которые мне трудно (или кому-либо еще) читать. Измените исходный вопрос и добавьте эти дополнительные методы и журнал сбоев/backtrace. –

ответ

0

Проблема, скорее всего, в самом деле ваш fetchedResultsController (вы используете ARC?), что fetchedResultsController a "strong" свойство?

Или может быть просто, что ваш fetchedResultsController не имеет объектов, и вы настаиваете на том, что у вас есть только один объект в вашем методе «numberOfSectionsInTableView», независимо от истинного содержимого «fetchedResultsController».

Попробуйте эту новую & улучшенную функцию:

-(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]; 
    } 

    if(cell == nil) 
    { 
     // this should never happen, but just in case... 
     NSLog(@"cell is still - unexpectedly - nil"); 
    } else { 
     if(self.fetchedResultsController == nil) 
     { 
      NSLog(@"surprise, fetchedResultsController is nil"); 
     } else { 
      Client * client = nil; 
      @try { 
       client = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
      } 
      @catch (NSException * e) { 
       NSLog(@"exception thrown while trying to fetch something from fetchedResultsController - %@ %@", [e name], [e reason]); 
      } 
      @finally { 
       clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)]; 
       clientNameLabel.tag = 1; 
       clientNameLabel.backgroundColor = [UIColor clearColor]; 
       clientNameLabel.textColor = [UIColor whiteColor]; 
       clientNameLabel.font = [UIFont boldSystemFontOfSize:13]; 
       clientNameLabel.text = client.clientName; 
       [cell.contentView addSubview:clientNameLabel]; 

       clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)]; 
       clientAccountNumberLabel.tag = 2; 
       clientAccountNumberLabel.textColor = [UIColor whiteColor]; 
       clientAccountNumberLabel.backgroundColor = [UIColor clearColor]; 
       clientAccountNumberLabel.font = [UIFont boldSystemFontOfSize:13]; 
       clientAccountNumberLabel.text = client.clientAccountNumber; 
       [cell.contentView addSubview:clientAccountNumberLabel]; 

       clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)]; 
       clientTelephoneNumberLabel.tag = 3; 
       clientTelephoneNumberLabel.textColor = [UIColor whiteColor]; 
       clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor]; 
       clientTelephoneNumberLabel.font = [UIFont boldSystemFontOfSize:13]; 
       [cell.contentView addSubview:clientTelephoneNumberLabel]; 

       addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
       addressLine1Label.tag = 4; 
       addressLine1Label.textColor = [UIColor whiteColor]; 
       addressLine1Label.backgroundColor = [UIColor clearColor]; 
       addressLine1Label.font = [UIFont boldSystemFontOfSize:13]; 
       addressLine1Label.text = client.addressLine1; 
       [cell.contentView addSubview:addressLine1Label]; 

       addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
       addressLine2Label.tag = 5; 
       addressLine2Label.textColor = [UIColor whiteColor]; 
       addressLine2Label.backgroundColor = [UIColor clearColor]; 
       addressLine2Label.text = client.addressLine2; 
       addressLine2Label.font = [UIFont boldSystemFontOfSize:13]; 
       [cell.contentView addSubview:addressLine2Label]; 

       addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
       addressLine3Label.tag = 6; 
       addressLine3Label.textColor = [UIColor whiteColor]; 
       addressLine3Label.backgroundColor = [UIColor clearColor]; 
       addressLine3Label.font = [UIFont boldSystemFontOfSize:13]; 
       addressLine3Label.text = client.addressLine3; 
       [cell.contentView addSubview:addressLine3Label]; 

       addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; 
       addressLine4Label.tag = 7; 
       addressLine4Label.textColor = [UIColor whiteColor]; 
       addressLine4Label.backgroundColor = [UIColor clearColor]; 
       addressLine4Label.font = [UIFont boldSystemFontOfSize:13]; 
       addressLine4Label.text = client.addressLine4; 
       [cell.contentView addSubview:addressLine4Label]; 

      } 

      Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
     } 
    } 
    return cell; 
} 

(я фактически не проверить это ... но я положил некоторые новые проверки ошибок и обработки исключений в него для вас)

+0

Но зачем это делать, [FetchedObjects count] имеет в нем данные, вот что меня расстраивает! –

+0

OK !! Это сработало отлично, одна мелочь, почему это происходит, когда я обновляю значение изменения в другом контроллере представления, а затем возвращаюсь к этому представлению, данные не изменяются? это не имеет смысла, потому что у меня есть код поиска в - (void) viewWillAppear: (BOOL) Анимированный метод –

+0

Возможно, потому, что вы явно не указали таблице на «reloadData». Одно место для этого - в методе '' viewWillAppear: '' вашего родительского представления. –