I have a UI which contains a UITableView and a UIDatePicker. When I select a Row on my table it is highlighted, but as soon as I interact with the DatePicker (scroll to a new value) the row isn’t highlighted anymore. The value of the row is bound to that of the DatePicker. How can I permanently highlight the cell?
In the iCal-App -> Add -> Start&End I saw this behaviour.
I tried the selectRowAtIndex method in my ValueChanged-method of the picker. I thought that the highlighting is lost in this callback-method.
-(IBAction)setStartTimeMethod
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, dd. MMM yyyy HH:mm"];
if(!self.endDateRowSelected)
self.date = [dateFormat stringFromDate:[datePicker date]];
else
self.endDate = [dateFormat stringFromDate:[datePicker date]];
[dateFormat release];
// [self.tableView1 selectRowAtIndexPath:tableView1.indexPathForSelectedRow animated:NO scrollPosition:UITableViewScrollPositionTop];
[self.tableView1 reloadData];
}
Edit, my didSelectRowMethod
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE, dd. MMM yyyy HH:mm"];
if(indexPath.row == 0){
NSLog(@"Start");
self.endDateRowSelected = NO;
NSDate *startDate = [formatter dateFromString:self.date];
[datePicker setDate:startDate animated:YES];
//if(self.endDateRowSelected)
// [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}else if(indexPath.row == 2){
NSLog(@"End");
self.endDateRowSelected = YES;
if(self.endDate){
NSDate *endDateTime = [formatter dateFromString:self.endDate];
[datePicker setDate:endDateTime animated:YES];
}
}else{
self.endDateRowSelected = NO;
}
[formatter release];
// Won't work, doesn't allow highlighting a cell.
// [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
BR,
mybecks
The solution was quite easy.
In my
cellForRowAtIndexPathI must call theselectRowAtIndexPathmethod.The bool is set in my
didSelectRowAtIndexPath, depending on clicking on Start or End.I still reload the table in my pickerValueChanged delegate.
Thank you for time & help.