2012-06-09 2 views
0

코어 데이터 UITableView가 있습니다. 핵심 데이터 관리 객체에는 headerTitle, headerNumber, objectTitle, objectComment의 4 가지 속성이 있습니다.UITableView 섹션이 하나의 속성으로 정렬되고 제목이 다른 것으로 표시됩니다.

UITableView를 headerNumber로 구분하지만 titleForHeaderInSection은 headerTitle 속성으로 지정합니다. 현재 나는 다음이 코드 ....

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; 
    return [sectionInfo numberOfObjects]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    id <NSFetchedResultsSectionInfo> sectionInfo = [[__fetchedResultsController sections] objectAtIndex:section]; 
    return [NSString stringWithFormat:@"%@", [sectionInfo name]]; 
} 

- (NSFetchedResultsController *)fetchedResultsController 
{ 
    if (__fetchedResultsController != nil) { 
     return __fetchedResultsController; 
    } 

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    // Edit the entity name as appropriate. 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; 
    [fetchRequest setEntity:entity]; 

    // Set the batch size to a suitable number. 
    [fetchRequest setFetchBatchSize:20]; 

    // Edit the sort key as appropriate. 
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO]; 
    NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; 

    [fetchRequest setSortDescriptors:sortDescriptors]; 

    // Edit the section name key path and cache name if appropriate. 
    // nil for section name key path means "no sections". 
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"headerNumber" cacheName:@"Master"]; 
    aFetchedResultsController.delegate = self; 
    self.fetchedResultsController = aFetchedResultsController; 

    NSError *error = nil; 
    if (![self.fetchedResultsController performFetch:&error]) { 
     // Replace this implementation with code to handle the error appropriately. 
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 

    return __fetchedResultsController; 
} 

headerNumber가 headerTitle가 headerNumber의 말씀 인 2012 년 6 월에 201,206 같은 수치 연도와 월 예를 들면,이 "2012년 6월"

누구에게 어떤 제안이 있습니까?

답변

1

당신은 테이블보기에서

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section]; 

//return a view with uiLable and show your headerTitle there 

} 

을 headerTitle 속성을 보여주고 사용 Hopw이 당신에게

+0

감사합니다 도움이 될 것입니다 headerNumber 속성

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // put your code here } 

을 표시하기위한 방법을 다음이 다음과 같은 방법을 사용할 수 있습니다 .. 이것은 도움이됩니다. 아직 작동시키지 못했지만 지금은 올바른 방향으로 나아가고 있다고 생각합니다. – OscarTheGrouch

관련 문제