Я хочу, чтобы запускал reloadData
, когда запускается calendarDidDateSelected
, но это, похоже, не происходит. Насколько я могу судить, таблица настроена правильно, и я установил ее для обновления содержимого self.agendaTableArray
в cellForRowAtIndexPath
при перезагрузке. Что я делаю не так?UITableView reloadData не работает при нажатии кнопки
Я настраиваю таблицу следующим образом:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set up Day Agenda table
CGRect frame = CGRectMake(0,380,self.view.frame.size.width,self.view.frame.size.height);
UITableView *agendaTable = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
agendaTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
agendaTable.delegate = self;
agendaTable.dataSource = self;
[agendaTable reloadData];
[self.view addSubview:agendaTable];
/////
self.agendaTableArray = [[NSArray alloc] init];
self.agendaTableArray = @[@"No events today!"];
[self.calendar setMenuMonthsView:self.calendarMenuView];
[self.calendar setContentView:self.calendarContentView];
[self.calendar setDataSource:self];
}
Соответствующий cellForRowAtIndexPath
код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
///...earlier code snipped for brevity
// title of the item
if (self.datePicked == [NSNumber numberWithInt:16]) {
NSLog(@"cellForRowAtIndexPath says self.datePicked is 16");
self.agendaTableArray = @[@"Dinner with Rebekah", @"Meeting with John"];
}
else {
self.agendaTableArray = @[@"No events today!"];
}
cell.textLabel.text = self.agendaTableArray[indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14];
return cell;
}
calendarDidDateSelected
вызова, как так:
- (void)calendarDidDateSelected:(JTCalendar *)calendar date:(NSDate *)date
{
NSLog(@"Date: %@", date);
// NSDateFormatter is used to create a date from a string
// static keyword is used to avoid create a new instance each time calendarDidDateSelected is called
static NSDateFormatter *dateFormatter = nil;
if(!dateFormatter){
dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd"; // Read the documentation for dateFormat
}
// If date picked is June 16th
NSDate *juneSixteenth = [dateFormatter dateFromString:@"2015-06-16"];
if([juneSixteenth compare:date] == NSOrderedSame){
self.datePicked = [NSNumber numberWithInt:16];
NSLog(@"self.datePicked: %@", self.datePicked);
}
[self.agendaTable reloadData];
}
сделал таблицу данных о загрузке в первый раз? –
@VarunNaharia Yup. – TheDudeGuy
Вы пробовали отлаживать приложение и проверяли, достигли ли он линии 'self.agendaTableArray = @ [@« Ужин с Ревеккой », @« Встреча с Джоном »];' on tap? –