gpt4 book ai didi

ios - 点击按钮时 UITableView reloadData 不工作

转载 作者:行者123 更新时间:2023-11-29 12:20:05 27 4
gpt4 key购买 nike

我希望 self.agendaTablecalendarDidDateSelected 运行时运行 reloadData,但这似乎没有发生。据我所知,表格设置正确,我将其设置为在重新加载时更新 cellForRowAtIndexPathself.agendaTableArray 的内容。我做错了什么?

我正在像这样设置表格:

- (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];
}

最佳答案

您是否正确地将创建的 agendaTable 分配给 viewDidLoad 中的“agendaTable”属性?

self.agendaTable = agendaTable;

关于ios - 点击按钮时 UITableView reloadData 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30898548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com