objective-c - 在静态单元格上使用 UIDatePicker

标签 objective-c ios uistoryboard

我想在静态单元格上显示从 UIDatePicker 选取的日期。

screen

问题代码如下。我想通过使用 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/

相关文章:

objective-c - 是否断言在Objective C中成功创建了每个对象?

ios - XCode 5.1.1 iOS 7.1 将数据发送到任一先前的 Controller

ios - 无法更改 Storyboard 中 ViewController 的方向

iphone - 如何在场景 objective-c 之间传递信息

objective-c - UIImageView 和窗口方向问题

objective-c - count 是否是一个属性?

ios - 在 Swift 2 中解析 JSON 数据

android - 在 PhoneGap 1.2.0 中使用 Google Analytics 时 Android 和 iOS 之间的差异

ios - iPhone 应用程序在 didFinishLaunchingWithOptions 之前崩溃

ios - 修改静态 UITableView 单元格中的文本?