2015-02-03 1 views
1

나는 셀로 나눈 TableView를 가지고 있습니다. 셀의 텍스트는 UILocalNotification에 대한 fireDate입니다. 내 코드 :날짜로 UITableView의 섹션을 나누는 방법

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [[[UIApplication sharedApplication]scheduledLocalNotifications]count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{  
    cellView *cell = (cellView *)[tableView dequeueReusableCellWithIdentifier: @"Cell" forIndexPath:indexPath]; 
    NSArray *localnotifications = [[UIApplication sharedApplication]scheduledLocalNotifications]; 
    UILocalNotification *localNotification = [localnotifications objectAtIndex:indexPath.row]; 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"MM/dd/yyyy"]; 
    NSString *timeString = [formatter stringFromDate:localNotification.fireDate]; 
    [cell.textlabel setText:timeString]; 
    return cell; 
} 

섹션을 날짜로 나눈 생성 방법은 무엇입니까?

+0

이것은이 게시물과 비슷합니다. http://stackoverflow.com/questions/11053741/ios-uitableview-sections-based-on-date-ranges –

답변

0

먼저 당신의 섹션 번호는 배열의 수

  • (NSInteger) numberOfSectionsInTableView해야합니다 : (jQuery과 *)있는 tableView { // 섹션의 수를 돌려줍니다. return [[[UIApplication sharedApplication] scheduledLocalNotifications] count]; }

행의 수는 다음

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return 1; 
} 

내가 당신 배열의 구조를 잘 모릅니다 각 섹션하지만 자사의 경우 이름을 섹션 당 하나 여야합니다 사전 예 : objectForKey : @ "날짜"...

- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    return [NSString stringWithFormat:@"%@", [[[UIApplication sharedApplication]scheduledLocalNotifications] objectAtIndex:section]; 
} 
cellForRowAtIndexPath에서

먼저

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{  
    switch (indexPath.section) { 
     case indexPath.row: 
     // fill your cell // 
     default: 
     break; 
    } 

} 

내가 당신을 말하고 테스트 나 근처에 컴퓨터가없는 당신 같은 개체는 일반적으로 하나 개의 섹션으로 수행 indexPath.section을 확인하고 을 설정 이 메모리에 의해 적어도 당신이 어떻게 tableView 작동 아이디어를 가지고 바랍니다.

모든 행운을 빕니다.

+0

코드가 작동합니다.하지만 문제는 2 개의 알림 동일한 날짜로 두 섹션을 만들 수 있습니다. 같은 날짜의 2 개의 알림이있는 섹션을 만들려면 어떻게해야합니까? –

관련 문제