2013-06-18 2 views
0

Я хочу создать календарь на основе недели, он должен показывать дни в UITableView как список. Ниже приведено изображение, которое я опубликовал, чтобы очистить требуемый результат. Прошли через Google много, но не получили никакого решения. enter image description here. Поехали много календарей KAl, Tapku, а также Mukhu, но не получили никакого решения для этого. Пожалуйста, направляйте.Как создать такой календарь

+3

Похоже, я был относительно прямым видом на стол. Вам не нужен «пакет». –

+0

сначала принесите ошибку, затем поставите свой вопрос здесь, и у вас есть помощь/решение, связанное с вашей дорогой дорогой :) – iPatel

+0

@Hot Licks Я согласен с вами, но как вы можете дать какое-либо представление об этом. –

ответ

0

Я что-то придумал с помощью таблицы. Основное поведение, которое вы ищете, - это добавить строки при выборе даты (и скрыть ранее выбранные). Я сделал tableView с разделом для каждого дня и добавил события под ним.

Я добавил TableView из xib, но должен был сделать это в коде для этой настройки.

// 
// TCViewController.m 
// TableCalendarTest 
// 
// Created by Brian Broom on 6/18/13. 
// Copyright (c) 2013 Brian Broom. All rights reserved. 
// 

    #import "TCViewController.h" 

    @interface TCViewController() 
    { 
     int selectedSection; 
    } 
    @end 

    @implementation TCViewController 

    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view, typically from a nib. 


    } 

    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
    } 

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

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     if (section == selectedSection) { 
      return 3; 
     } else { 
      return 1; 
     } 
    } 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if (indexPath.row == 0) { 

      [tableView beginUpdates]; 
      [self.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:selectedSection] animated:YES]; 
      NSMutableArray *oldRows = [[NSMutableArray alloc] init]; 

      [oldRows addObject:[NSIndexPath indexPathForRow:1 inSection:selectedSection]]; 
      [oldRows addObject:[NSIndexPath indexPathForRow:2 inSection:selectedSection]]; 

      selectedSection = indexPath.section; 

      [tableView deleteRowsAtIndexPaths:oldRows withRowAnimation:UITableViewRowAnimationTop]; 


      NSMutableArray *newRows = [[NSMutableArray alloc] init]; 

      [newRows addObject:[NSIndexPath indexPathForRow:1 inSection:selectedSection]]; 
      [newRows addObject:[NSIndexPath indexPathForRow:2 inSection:selectedSection]]; 

      [tableView insertRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationBottom]; 
      [tableView endUpdates]; 
     } 
    } 

    - (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 (indexPath.row == 0) { 
      [cell.textLabel setText:[NSString stringWithFormat:@"Day"]]; 
     } else { 
      [cell.textLabel setText:[NSString stringWithFormat:@"Event %d", indexPath.row]]; 
     } 


     return cell; 
    } 

    @end 

Незначительная часть получает информацию о дате и настройку.

+0

Вы неправильно поняли вопрос, я не ищу настройки tableview, но для настройки календаря в tableview. –

1

Чувак попробовать это в течение недели и день зрения

https://github.com/muhku/calendar-ui?

Неделя дня или дня может начать работать с вами или если вы хотите начать заново получать события из iOS EventStore и создавать источник данных, который передает данные в вашу таблицу. В основном все компоненты календаря делают это, вы можете даже взять это из вышеуказанного компонента.

Используйте эти методы, чтобы сделать даты:

#define DATE_COMPONENTS (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit) 

#define CURRENT_CALENDAR [NSCalendar currentCalendar] 

+ (NSDate *)nextDayFromDate:(NSDate *)date { 
    NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date]; 
    [components setDay:[components day] + 1]; 
    [components setHour:0]; 
    [components setMinute:0]; 
    [components setSecond:0]; 
    return [CURRENT_CALENDAR dateFromComponents:components]; 
} 

+ (NSDate *)previousDayFromDate:(NSDate *)date { 
    NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:date]; 
    [components setDay:[components day] - 1]; 
    [components setHour:0]; 
    [components setMinute:0]; 
    [components setSecond:0]; 
    return [CURRENT_CALENDAR dateFromComponents:components]; 
} 

Организация даты в неделю - группе те даты, чтобы сформировать в неделю. Примите этот метод, используя этот метод:

+ (NSString *)dayNameForWeekDay:(int)weekday 
{ 
    switch (weekday) { 
     case 1: 
      return @"Sunday"; 
      break; 
     case 2: 
      return @"Monday"; 
      break; 
     case 3: 
      return @"Tuesday"; 
      break; 
     case 4: 
      return @"Wednesday"; 
      break; 
     case 5: 
      return @"Thursday"; 
      break; 
     case 6: 
      return @"Friday"; 
      break; 
     case 7: 
      return @"Saturday"; 
      break; 
     default: 
      break; 
    } 

    return @""; 
} 

И используя источник данных, покажите события. Настройка вашей таблицы не имеет большого значения, расширение коллапса настолько прост.

+0

Спасибо, я прохожу через него, а потом приходи к тебе. –

+0

Я не понимаю, как я получаю, вы используете делегатов календаря, чтобы получить даты, и мне нужно отобразить таблицу, чтобы показать эти даты, скрывая представление календаря, беря на экран представление таблицы. Правильно ли? –

+0

Да, вы правы, вы бы потребляли данные у делегатов Eventkit и заполняли это табличное представление – satheeshwaran

Смежные вопросы