2012-06-24 1 views
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

    } 



     [cell setBackgroundColor:[UIColor lightGrayColor]]; 
     cell.textLabel.textColor = [UIColor lightTextColor]; 
     cell.textLabel.backgroundColor = nil; 
     cell.detailTextLabel.textColor = [UIColor darkGrayColor]; 
     cell.detailTextLabel.backgroundColor = nil; 

    // Get list of local notifications 
     NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; 
     UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row]; 

     // Display notification info 
     [cell.textLabel setText:notif.alertBody]; 

     NSDateFormatter *format = [[NSDateFormatter alloc] init]; 
     [format setDateFormat:@"MMM dd 'at' HH:mm"]; 

     NSString *dateString = [format stringFromDate:notif.fireDate]; 

     NSString *textData = [[NSString alloc]initWithFormat:@"%@",dateString]; 

     [cell.detailTextLabel setText:textData]; 

     //[notif.fireDate description] 



     [self.tableView reloadData]; 
     return cell; 

    } 

모든 것을 아주 이상한 문제는 내가 쓰기 해달라고하면 absoloutely 정상 간다 "[self.tableView reloadData]은,"나는한다면합니다 (셀이 있지만이 표시되지처럼, 그러나 보인다 셀 분리자는 테이블 뷰의 셀 수에 따라 사라집니다.아이폰 OS -있는 tableView realodData

사용자가 뷰를 벗어나서 뷰를 다시로드하여 업데이트 된 정보를 표시 할 필요가 없도록 reloadData를 사용해야합니다.

의견이 있으십니까? 당신은 cellForRowAtIndexPath 내부 [self.tableView reloadData];를 추가 할 필요가없는

+0

Omar가 말했듯이 이것은 데이터를 다시로드하는 잘못된 장소입니다. 'newItem' 메쏘드를 만들고 거기에'[tableView reloadData]'를 대신하십시오. 또는 항목을 제거/지울 때. – Hassan

+0

예를 들어 주시겠습니까? –

+0

'reloadData'는 테이블 뷰에게 컨트롤러에서 데이터를 다시 불러 오도록 지시하는 데에만 사용됩니다 (즉, 위에서 게시 한 것과 같은 일부 대리자 메소드가 호출 됨). 아직이 기능이 없다면 [this] (http://www.iphonesdkarticles.com/2009/01/uitableview-creating-simple-table-view.html)을보십시오. – Hassan

답변

3

이 다시 아주 이상한 문제

일반적으로

모든 변경할 때마다 일반적으로 [self.tableView reloadData]; 전화를 만들 것입니다 당신이 경험으로 cellForRowAtIndexPath를 호출합니다 reloadData를 호출하기 때문에, 절대적으로 잘못된 것입니다 또는 일부 내용을 참조하십시오. UITableView

+0

다른 곳에서는 다시로드 할 수 있습니까? –

+0

예를 들어, 버튼의 touchUpInside 또는 viewWillAppear –

1

새 데이터를 사용할 수 있는지 확인하는 기능을 만듭니다 (새로 고침 버튼을 구현하거나 새로 고침하려면 끌어 올 수 있음). 새로운 데이터가있는 경우 [self.tableView reloadData];으로 전화하십시오.