我想在静态单元格上显示从 UIDatePicker 选取的日期。
问题代码如下。我想通过使用 UIDatePicker 更改日期来更改 self.label.text
,但它没有改变。
- (IBAction)inputDate:(id)sender {
self.label.text = [NSString stringWithFormat:@"%@", self.datePicker.date];
}
- 方法
inputDate:
连接到 UIDatePicker。 - 属性
datePicker
也连接到 UIDatePicker。
有什么具体的方法可以改变静态单元格吗?谢谢你的好意。
最佳答案
我建议您将要更改的单元格存储为 TableView 中的 ivar:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//...
// configure your birth date cell
self.birthDateCell = cell;
//...
}
那么你的方法看起来像这样:
- (IBAction)inputDate:(id)sender {
self.birthDateCell.label.text = [NSString stringWithFormat:@"%@", sender.date];
}
那应该就可以了。此外,请确保您使用日期选择器的适当事件操作调用 inputDate 函数。
编辑:此外,您可能需要重新加载单元格以显示数据,如下所示:
- (IBAction)inputDate:(id)sender {
self.label.text = [NSString stringWithFormat:@"%@", sender.date];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:NO];
}
关于objective-c - 在静态单元格上使用 UIDatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11770443/