2012-02-26 12 views
3

코어 데이터를 사용하여 프로젝트 이름을 저장하고이를 테이블보기에 표시하고 있습니다. 테이블 뷰가 비어 있으면 (데이터베이스에 데이터 없음) 비어 있습니다. 사용자 관점에서 보면별로 좋지 않으므로 "No Projects"라는 레이블을 표시 할 수 있기를 원합니다.테이블 뷰가 비어있는 경우 레이블 표시

어떻게하면됩니까? 데이터베이스가 비어 있음을

  1. 확인이 BOOL가 true로 설정되어있는 경우 BOOL에게
  2. 을 설정하거나 YES, 레이블을 보여 내가해야? 또는 cell.textLabel.text를 "No Projects"로 설정하십시오.

올바른 트랙에 있다면 적절한 방향으로 밀어주는 예제 코드를 보내 주시면 감사하겠습니다.

감사

+1

당신은 무엇을 시도 했습니까? – sch

+0

당신은 받아 들여지지 않았습니다, 무슨 일이 일어 났습니까? – QED

+0

다른 방법을 사용했습니다 - 게시하려면 – jcrowson

답변

3

나는 내 핵심 데이터베이스가 비어 있는지 확인하려면 다음 코드를 사용하여 끝났다. 훌륭하게 작동합니다. 이것은 CoreDataController.m 파일에 있어야합니다.

NSLog(@"Total number of rows = %d ", totalNumberOfRowsInDatabase); 

    if (totalNumberOfRowsInDatabase == 0) 
    { 

     NSLog(@"Database is empty"); 
     UIImage *image = [UIImage imageNamed:@"emptyTable.png"]; 
     UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
     [imageView setFrame:self.tableView.bounds]; 
     [self.tableView setBackgroundView:imageView]; 
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
     [self.tableView setBackgroundColor:[UIColor clearColor]]; 

    } 
    else 
    { 
     [self.tableView setBackgroundView:nil]; 
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 
     [self.tableView setBackgroundColor:[UIColor whiteColor]]; 
    } 

    return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects]; 
1
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section == mySection) return MAX(dataCount, 1); 
    else // yadda 
} 


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    // yadda 

    if ([indexPath section] == mySection) { 
     if (dataCount == 0) return mySpecialCell; 
    } 


    // yadda 
} 
+0

mySection은이 "No Projects"행을 표시하려는 섹션을 의미합니다. 아마도 if 0. if 문은 셀을 올바른 섹션에 넣고 있는지 확인하는 것입니다. – QED

+0

표시해야하는 데이터 레코드의 수를 나타내는 기호임을 의미합니다. 0이면 데이터베이스가 비어 있습니다. 다음으로'mySpecialCell'이 무엇인지 물어볼 것입니다. – QED