I am trying to update the date and time displayed in a table cell immediately after the UIPicker's data has changed (real time updated). I implemented the following code. My "update" method is not being called despite changing the values in the picker. Can anyone advise? Thanks!
Zhen
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0)
{
self.picker.hidden = NO;
[self.picker addTarget:self action:@selector(updateDate) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)updateDate
{
selectedDate = [self.picker date];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd-MM-yyyy HH:mm"];
selectedDateString = [formatter stringFromDate:selectedDate];
[tableView reloadData];
}
You need to put a colon after the selector name.
[self.picker addTarget:self action:@selector(updateDate:) forControlEvents:UIControlEventTouchUpInside];
Also, the updateDate method should take an object of type id.
- (void) updateDate:(id) obj { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With